C# Windows Control

hey ppl, i am having a problem with a control, my control is a background with a label on it, then when i use my control on my form i use the on click event, and it only happens when u click the control itself and not the label, so i was wondering how can i do that no matter where u click inside the control , fires the click event.

pls post me some code :(

mig16

thx


Answer this question

C# Windows Control

  • ozan celikada

    i have my user control and my label mouseDown and mouseUP event in this events:

    [code lang="C#"]private void MigBtn_MouseDown(object sender, MouseEventArgs e)
    {
    if (e.Button == MouseButtons.Left)
    {
    mouseDown = true;
    this.Invalidate();
    }
    }

    private void MigBtn_MouseUp(object sender, MouseEventArgs e)
    {
    if (e.Button == MouseButtons.Left)
    {
    mouseDown = false;
    this.Invalidate();
    }
    }[/code]

    the label have that events and also the user control, but this is not the problem, the problem is when i add the control to a form and i assign the mouseDown event for the control, it just fires when u click on the user control area, when u click on the label area it draws an effect like u clicked but it doesnt fire the event in my form.


    if u want an example here is the program and u will se that it works like a button allways but when u click on the label area, im looking for the way to merge label and user control :(

    HERES THE EXAMPLE:

    http://usuarios.lycos.es/mig16/ConfigBtn.zip

    mig16

  • Frank213

    In your UserControl you are handling the Click event, but when you click on the label the click event is not getting fired because the label was clicked. You can do this:

    this.Click += new EventHandler(MyUserControl_Click);
    this.label1.Click += new EventHandler(MyUserControl_Click);

    Just make the label handle the same event that your UserControl is handling. Now no matter where you click on the UserControl it will work now.

    Cheers,

    Aaron
    http://aaronfeng.blogspot.com/

  • 78Spit1500Fed

    im allready doing that, thats not the problem, on my control source code i handle those events, the problem is at the runtime, when i add that control to a form and i use the click event, it just happens when u click on the user control area and not when u click on the label area. pls some 1 help me

    thx

    mig16

  • nullsmind

    Have you really connected the clickevent handler to the label that you are attaching to the form

    Is what the event handler does really the same if the label is the sender

    I.e., show your code! :)

     

     


  • projecttoday

    Looks like a focus problem. Depending on the rest of yoru code the effect of the call to Invalidate may just be waiting while the label has focus.


  • C# Windows Control