Label control that set the focus to the related Textbox on the mousehover event
-
Hello, I like to create a Label control with an property in which I can select the available controls on the Form (except for the Label controls). One the respective control is set in Design time, this control will get the focus in Runtime when the user moves with the mouse over the Label control I'm fairly new with creating Usercontrols. Can anyone help me? Kind regards Arjen
-
Hello, I like to create a Label control with an property in which I can select the available controls on the Form (except for the Label controls). One the respective control is set in Design time, this control will get the focus in Runtime when the user moves with the mouse over the Label control I'm fairly new with creating Usercontrols. Can anyone help me? Kind regards Arjen
This might be helpful to you: Custom Controls in Visual C# .NET
Thanks Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
-
Hello, I like to create a Label control with an property in which I can select the available controls on the Form (except for the Label controls). One the respective control is set in Design time, this control will get the focus in Runtime when the user moves with the mouse over the Label control I'm fairly new with creating Usercontrols. Can anyone help me? Kind regards Arjen
Hello, Just came across your interesting question. If I got it write, I think you need to deal with inherited controls and a customzied property editor. I will try to give you an idea of how you can solve your problem, but will not sneak into the time costing details (I will mark them for you).
ArjenGroeneveld wrote:
like to create a Label control
What you need first is a custom label which derives from
Forms.Label
.public class LabelExtended : System.Windows.Forms.Label
{
...
}ArjenGroeneveld wrote:
One the respective control is set in Design time,
To make it easy (for me), I will use a string property to hold the name of this selected control (how we do this will be next).
private string selectedControlName = string.Empty;
[
CategoryAttribute("Arjens Properties"),
DescriptionAttribute("Holds the name of the selected control."),
DefaultValueAttribute(""),
EditorAttribute(typeof(SelectControlEditor), typeof(UITypeEditor)) // this is the key
]
public string SelectedControlName
{
get { return selectedControlName; }
set { selectedControlName = value; }
}ArjenGroeneveld wrote:
an property in which I can select the available controls on the Form (except for the Label controls).
We just added an
EditorAttribute
to the property. This is a type ofSelectControlEditor
and derives fromUITypeEditor
, which we have to create now.using System;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.ComponentModel;
using System.Drawing.Design;
...
public class SelectControlEditor : UITypeEditor
{
...
}What I want to show you is a
DropDown
editor, where you are able to select a control out of a list of control names. First we give the editor class the information about theDropDown
, by overriding theGetEditStyle
method like this:public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
if( context != null ) return UITypeEditorEditStyle.DropDown;
return base.GetEditStyle(context);
}Now we need to tell the editor how to edit your property, by overriding the
EditValue
method.public override object EditValue(ITypeDescriptorContext context, IServiceProvider provid