Custom control and handler

vb .net , custom control , handler Ljubljana, Slovenia
  • 12 years ago
    Hi all, I am working on an app which will display custom controls (just a picbox and label) i created in a tablelayoutpanel. because I am adding controls programatically I need to assign it a click method. I know how to do that but the problem is that it only fires if the control (not the actual picture box or label) is clicked if I click on a picture box on control it doesn't fire. I thought that if I create a custom control that on outside it acts as one homogene control. Private Sub DeviceData_Click(ByVal sender As Object, ByVal e As System.EventArgs) System.Windows.Forms.MessageBox.Show("test") End Sub AddHandler _DeviceData.Click, AddressOf DeviceData_Click Thanks for any help. Regards, Greg
  • 12 years ago
    Try to disable picture box. But if this will not help properly, you must handle internal controls and in handle routines you simply RaiseEvent Me.Click ... for doing that programatically you can For Each ctrl in Me.controls ... in sub new
  • 12 years ago
    so you cannot fire directly your usercontrol's click event. in this case you must create e.g. BuchClick event for your UserControl, and bring all clickEvents (also UserControl's) together in one handler, which rises your BunchClick... Tip: you can still recognize source object if your BunchClick preserves classical click handler interface (object,eventArgs).
  • 12 years ago
    I don't quite understand what you ment with the rest of suggestions, but disabling picture box helped!!! :) thanks a lot
  • 12 years ago
    the rest is quite more valid solution than disabling :)
    I will try to show it via pseudocode
    Class myUserCtrl
    {
    withevents myPictureBox, myLabel
    public event BunchClick(sender, e as eventArgs)

    Sub myPictureBox_Click(sender, e) Handles myPictureBox.Click
    {
    raiseevent BunchClick(sender, e)
    }

    Sub myLabel_Click -- the same handler as mypicturebox

    Sub myUserControl_Click -- the same
    }

    Class myFormWithUserControl
    {
    Sub myUserControl_BunchClick(sender, e) Handles myUserControl.BunchClick
    ...
    }



    Or as I told, you can bypass creating of each handler for userControl's children controls, when creating only MyUserControl_Click handler and in sub new of userControl, you can use

    For each ctrl as control in Me.Controls
    addHandler ctrl.click, AddressOf me.MyUserControl_Click

    raisning BunchClick from this universal handler stays the same as in pseudocode...
  • 12 years ago
    ah, it replaced underScore with bunch of LineFeeds :)
  • 12 years ago
    Thanks, I forgot to post an reply earlier but I figured it out after all (using your suggestion in first post) Thanks again for effort Greg

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter” - Eric Raymond