Solved

Capture button events from Usercontrol in Form in VB.NET

Posted on 2004-04-12
5
316 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

738 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