Solved

Capture button events from Usercontrol in Form in VB.NET

Posted on 2004-04-12
5
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 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