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
Solved

Capture button events from Usercontrol in Form in VB.NET

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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 …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 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