|
-
Sep 27th, 2009, 07:26 PM
#1
Thread Starter
Addicted Member
Raise Event and OnClick
I have a button that I need to use twice, the first time I click it, it validates that a string inside a textbox is a certain length. That part works. What I want to do is press the same button again but when I press it the second time it is suppose to popup a hidden label. But when I try to use a raiseevent command it gives me an error saying "the button is not an event in my program" can any tell me what I am doing wrong.
Or tell me how to use the OnClick
-
Sep 27th, 2009, 07:40 PM
#2
Frenzied Member
Re: Raise Event and OnClick
If you do that you'll end up with a non-standard UI which will confuse your users.
However, if you just really want to do that a simple way would be to use a static boolean variable in the click event that is already provided.
Each time the event is raised you can respond as per the value of the boolean.
Simply continually change the boolean from true to false to true...each time the button is clicked and then do as you please with the code.
-
Sep 27th, 2009, 07:43 PM
#3
Re: Raise Event and OnClick
try this:
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Static clicks As Integer = 1
If clicks = 1 Then
'check your textbox
clicks += 1
Else
Label1.Visible = True 'or however you're revealing your hidden label
End If
End Sub
edit: or use a boolean as fourblades suggested
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 27th, 2009, 07:44 PM
#4
Thread Starter
Addicted Member
Re: Raise Event and OnClick
Ok how would I go about doing this
-
Sep 27th, 2009, 07:48 PM
#5
Thread Starter
Addicted Member
Re: Raise Event and OnClick
It is a program I am trying to write I have two button a submit button and a reset button. I enter a string into a textbox and press the submit button and if the string isn't the right lenght I get an error an a message box. After I press ok in the message box to get it off the screen I should press the reset button to clear the textbox. But if i don't press the reset button and press the submit button instead thats when the label is suppose to popup saying "please press the reset button".
-
Sep 27th, 2009, 07:51 PM
#6
Frenzied Member
Re: Raise Event and OnClick
Well then ignore my previous post.
What you want is different than what I thought.
-
Sep 27th, 2009, 07:53 PM
#7
Thread Starter
Addicted Member
Re: Raise Event and OnClick
Ok thanks I have figures out the rest of the program this is the only part that is giving me trouble I guess I will have to try to keep searching
-
Sep 27th, 2009, 07:58 PM
#8
New Member
Re: Raise Event and OnClick
Code:
Public Class frm_project
Dim WarningLabel As Boolean = False
then inside your private sub button, check for the boolean value before any other part of your statement. Then check the uservalue
Code:
If WarningLabel = True Then
lbl_ClearWarn.Visible = True
ElseIf uservalue.Length <> 12 Then
WarningLabel = True
MessageBox.Show("bla bla bla")
then set your Reset button to put the Boolean back to False, as well as your Label.Visible to False
Code:
WarningLabel = False
txt_UserWords.Text = "Reset Button"
'Clear the Red/Blue Warning Box
If lbl_ClearWarn.Visible = True Then
lbl_ClearWarn.Visible = False
End If
-
Sep 27th, 2009, 08:29 PM
#9
Frenzied Member
Re: Raise Event and OnClick
I think this will work:
Code:
Public Class Form1
Private MessageboxAlreadyShown As Boolean
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Me.Label1.Visible = False
End Sub
Private Sub ButtonSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSubmit.Click
If Not Me.TextBox1.Text.Length = 20 Then
Select Case True
Case MessageboxAlreadyShown = True
Me.Label1.Visible = True
Case MessageboxAlreadyShown = False
MessageBox.Show("Error Message")
MessageboxAlreadyShown = True
End Select
Else
'continue processing
MessageboxAlreadyShown = False
End If
End Sub
Private Sub ButtonReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReset.Click
Me.TextBox1.Text = String.Empty
Me.Label1.Visible = False
MessageboxAlreadyShown = False
End Sub
End Class
-
Sep 27th, 2009, 08:38 PM
#10
Frenzied Member
Re: Raise Event and OnClick
Ooops minor problem. This will work as a user would expect:
Code:
Public Class Form1
Private MessageboxAlreadyShown As Boolean
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Me.Label1.Visible = False
End Sub
Private Sub ButtonSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSubmit.Click
If Not Me.TextBox1.Text.Length = 20 Then
Select Case True
Case MessageboxAlreadyShown = True
Me.Label1.Visible = True
Case MessageboxAlreadyShown = False
MessageBox.Show("Error Message")
MessageboxAlreadyShown = True
End Select
Else
Me.Label1.Visible = False
'continue processing
End If
End Sub
Private Sub ButtonReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReset.Click
Me.TextBox1.Text = String.Empty
Me.Label1.Visible = False
MessageboxAlreadyShown = False
End Sub
End Class
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
|