|
-
Oct 16th, 2006, 09:04 PM
#1
Thread Starter
New Member
[02/03] What Button on Another Form Did I click?
Hi,
I have done this in VB6 but can't find the syntax in VS 2003. I have a form (choice form) that has two buttons that both open another form (a search form). One button is supposed to open a basic search and the other is supposed to open a flash search.
I can't find a simple way to determine which button I've pressed on the other form. I am guessing it's hiding somewhere in the sender event but I just can't get to it.
My other option is to use a hidden label on the "choice" form that has text saying which is clicked but I can't figure out how to access the value of the hidden label once I am on the second "search" form.
Can anyone help me with these tasks?
Thanks,
Andrew
Andrew - Probably Using VB.NET 2003 and Most Likely 
-
Oct 16th, 2006, 09:29 PM
#2
Re: [02/03] What Button on Another Form Did I click?
If you show the searchForm by ShowDialog mode then you can assign the seachForm dialog result to OK or what ever you want and after the form is closed you can check which button was clicked.
VB Code:
'Form 1
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fr2 As New Form2
If fr2.ShowDialog = Windows.Forms.DialogResult.OK Then
'The OK button was clicked
End If
End Sub
End Class
and
VB Code:
'Form 2
Public Class Form2
Private Sub ButtonOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOK.Click
Me.DialogResult = Windows.Forms.DialogResult.OK
Me.Close()
End Sub
End Class
-
Oct 16th, 2006, 09:35 PM
#3
Re: [02/03] What Button on Another Form Did I click?
If you need to know from a different form, some fact about the first form. Well, another way to put that would be that you want to know a property of the first form. So why not use a ReadOnly property added to the first form that exposes a boolean or integer that informs you which button was pressed. Offhand, I can't think of a way to do this other than to have a member variable on the first class that holds this. You would set the variable in the button click, and expose the variable through the property.
My usual boring signature: Nothing
 
-
Oct 16th, 2006, 09:36 PM
#4
Re: [02/03] What Button on Another Form Did I click?
Sorry, are you saying that in form1 you have two buttons that both open form2, but form2 is supposed to behave differently depending on which button you pressed? If so then you need to think of this slightly differently. form2 doesn't actually care what button is pressed. It only cares what it is told to do. You might want to actiavet the same functionality from a menu item or something else completely unrelated to either button. You need a way to pass an instrcution to this form. The most logical way to do that is through the constrcutor. You write one or more constructors that take parameters that control how the form behaves. If you only have two choices then you might have one argument of type Boolean:
VB Code:
Public Sub New(ByVal flash As Boolean)
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
If flash Then
'Perform a flash search.
Else
'Perform a basic search.
End If
End Sub
You then pass a Boolean value to the form when you create it. The basic button would pass False to the argument and the flash button would pass True.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|