Results 1 to 10 of 10

Thread: Raise Event and OnClick

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2009
    Posts
    133

    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

  2. #2
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    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.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Raise Event and OnClick

    try this:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Static clicks As Integer = 1
    3.     If clicks = 1 Then
    4.         'check your textbox
    5.         clicks += 1
    6.     Else
    7.         Label1.Visible = True 'or however you're revealing your hidden label
    8.     End If
    9. End Sub

    edit: or use a boolean as fourblades suggested

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2009
    Posts
    133

    Re: Raise Event and OnClick

    Ok how would I go about doing this

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2009
    Posts
    133

    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".

  6. #6
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: Raise Event and OnClick

    Well then ignore my previous post.
    What you want is different than what I thought.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2009
    Posts
    133

    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

  8. #8
    New Member
    Join Date
    Sep 2009
    Posts
    2

    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

  9. #9
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    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

  10. #10
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    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
  •  



Click Here to Expand Forum to Full Width