Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Label control that set the focus to the related Textbox on the mousehover event

Label control that set the focus to the related Textbox on the mousehover event

Scheduled Pinned Locked Moved C#
designhelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ArjenGroeneveld
    wrote on last edited by
    #1

    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

    M M 2 Replies Last reply
    0
    • A ArjenGroeneveld

      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

      M Offline
      M Offline
      Md Marufuzzaman
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • A ArjenGroeneveld

        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

        M Offline
        M Offline
        Martin 0
        wrote on last edited by
        #3

        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 of SelectControlEditor and derives from UITypeEditor, 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 the DropDown, by overriding the GetEditStyle 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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups