?
Solved

Capture button events from Usercontrol in Form in VB.NET

Posted on 2004-04-12
5
Medium Priority
?
320 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 150 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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 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