|
-
Nov 10th, 2009, 12:32 AM
#1
Thread Starter
Addicted Member
Button Click as condition
Hey All,
Is it possible to use a button click event as a condition? Maybe set a bool flag to true if someone clicks it?
Just wondering.
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
Nov 10th, 2009, 12:49 AM
#2
Re: Button Click as condition
You don't use an event as a condition. The event is raised and you handle it by registering a method using either the Handles clause or the AddHandler statement. Normally for a Button you just double-click it in the desinger and the event handler is created for you, complete with Handles clause.
What you do in that event handler is up to you. If you want to set a Boolean variable to True then by all means do so.
-
Nov 10th, 2009, 12:57 AM
#3
Fanatic Member
Re: Button Click as condition
How is it that you want to use this?
That will help us answer. Of course you can set a Boolean flag if someone clicks a button, but there are probably better ways to accomplish whatever it is you would be doing that way.
Are you trying to allow an external (Client) class to know when said button is pushed?
Imagine Form1:
Code:
Public Class Form1
'The WithEvents Keyword allows your client (Form1) to "Listen" for
'Events sourced by the variable instance of Form2, as long as the instance
'is Initialized within the scope of Form1
Private WithEvents frm2 As Form2
Private Sub Form1Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Form1Button.Click
'Create an instance of Form2:
frm2 = New Form2
frm2.Show()
'frm2 will "Show" Until it is closed, or until the button is clicked,
'in which case the ButtonClick Event on frm2 will Raise a CUSTOM
Event, which will be "Heard" by Form1 . . .
End Sub
'This is the HANDLER for the Custom Event sourced by frm2:
Private Sub OnForm2ButtonClick(ByVal Sender As Object, ByVal e As System.EventArgs) Handles frm2.Form2ButtonClicked
frm2.Close()
frm2 = Nothing
MsgBox("The Button on Form 2 was just Clicked")
End Sub
End Class
Now here's Form2:
Code:
Public Class Form2
'Declare a Custom Event (Use the Event Signature standard Sender/e):
Public Event Form2ButtonClicked(ByVal Sender As Object, ByVal e As System.EventArgs)
'In the Form2Button EventHandler, Raise your custom event:
Private Sub Form2Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Form2Button.Click
RaiseEvent Form2ButtonClicked(Me, e)
End Sub
End Class
There is more to all this event handling stuff, but this is some basics. Not sure if that is what you are trying to accomplish. If it IS, then consider whether you can get away with using the ShowDialog/DialogResult method instead. There ARE cases where you can't, but it is a cleaner way to do this, and allows you to use the "Using" Keyword when you instantiate your second form.
Hope that helped.
-
Nov 10th, 2009, 01:07 AM
#4
Thread Starter
Addicted Member
Re: Button Click as condition
yes just trying to determine if a button is clicked, which JM pretty much set it straight for me. All I have to do is declare a boolean flag, set it to false, and once inside the button_click event I can set that value to = true.
That seems simple enough.
I find that a lot of my problems with programming is lack of knowledge on the basic fundamental structures, classes, and variables.
You guys do a great job helping me out. Thanks.
Anyone got a good source for someone to learn the overall basics of programming syntax? A book I can buy or a good webpage? Not knowing the terminology, when to byval vs byref, and a vast asortment of other fundatmental programming lessons really slows me down.
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
Nov 10th, 2009, 01:21 AM
#5
Member
Re: Button Click as condition
Hi Abrium,
Check out this link.
http://www.homeandlearn.co.uk/NET/vbNET.html
Use this forum regularly. I also started with Zero knowledge of VB.net 3 months back. Using this vbforums, learned a lot. Guys here give good suggestion even on how to post ur querries.
-
Nov 10th, 2009, 01:29 AM
#6
Thread Starter
Addicted Member
Re: Button Click as condition
Hey Thanks a lot man. I'm about the same way, had VB 3 years ago and swore to myself I'd stay current on it... and of course lied to myself. Now I'm trying to fight through the advanced classes required for grad and its just KILLIN me! Great information here though thanks to people like JM and Runs.
I'm going to take a look at that link.
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
Nov 10th, 2009, 01:48 AM
#7
Fanatic Member
Re: Button Click as condition
Not sure if I mentioned it before, but I found that while the books published by Wrox can be a mixed bag, the one for VB 2005 named "Professional VB 2005" had a very good section on Classes, structures, events, and the like. Was OK for sytax and what not, but they did a good job on the conceptual stuff.
When I picked up the 2008 version, "Professional Visual Basic 2008", I was disappointed. While it seemed like what you would call a revision, the style was not as clear, and overall, the earlier book was more helpful (even though I am using vs 2008).
Don't know if you venture into SQL, but there is also a very good book on THAT too, Named "Professional SQL Server 2005 Programming".
For general Practices (and emphatically NOT specific to VB.NET, but REALLY good nonetheless, are books by Joel Spolsky. I am currently reading "Joel on Software", and he has another I haven't got yet titled "UI Design for the Programmer" (Or something close to that . . .).
It was difficult for me early on, because it seems like there are either REALLY REALLY basic books, or REALLY Heavy ones, and not much in betwween.
The folks here at the forums helped a LOT, too . . .
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
|