Solved

Capture button events from Usercontrol in Form in VB.NET

Posted on 2004-04-12
5
311 Views
Last Modified: 2008-02-01
I have made a usercontrol which have a button cmdButton which performs something on its cmdButton_Click event and stores the value in a Property. I am calling this usercontrol in a Windows Form in VB.NET . I want to capture the cmdButton_Click event of Usercontrol in Form and pass the Property value to the Form textbox control everytime it is clicked .
Please advise me how this can be implemented . Thanks in advance
0
Comment
Question by:ai4u
  • 3
5 Comments
 
LVL 2

Expert Comment

by:majodio
ID: 10804937
I'm not sure I completely understand your question, but here goes.

You will need to setup a delegate/Event in your user control and then handle that event in the form.  I'll create a small example and BRB.  :)
0
 
LVL 2

Accepted Solution

by:
majodio earned 50 total points
ID: 10804958
Put the following code in your usercontrol:

Public Event BtnClick As EventHandler

Public Sub cmdButton_Click(ByVal Sender as object, ByVal e as EventArgs) Handles cmdButton.Click
     RaiseEvent BtnClick(Sender, e)
End Sub


Then put the following code in your form:

Public Sub UserControl_Click(ByVal Sender as object, ByVal e as EventArgs) Handles UserControl.BtnClick
     ...  Do your stuff here ...
End Sub

I have not compiled the previous code so there may be a few errors, but I think you get the idea?
0
 
LVL 27

Expert Comment

by:planocz
ID: 10814436
Hi ai4u,

In your usercontrol use this to check button or key presses to the parent form the control is in ...

Example:

  Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Const WM_KEYDOWN As Integer = &H100
        Const WM_SYSKEYDOWN As Integer = &H104
        Dim e As System.EventArgs

        If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
            Select Case (keyData)
                Case Keys.Down
                    Me.Parent.Text = "Down Arrow Captured"
                Case Keys.Up
                    Me.Parent.Text = "Up Arrow Captured"
            end select
End Function
0
 
LVL 2

Expert Comment

by:majodio
ID: 11086291
The answer that I posted should solve the problem (if I understand him correctly).  Shouldn't the pts be distributed accordingly?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now