Results 1 to 4 of 4

Thread: change event when mouse is clicked outside a panel

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2013
    Location
    Newcastle, Australia
    Posts
    158

    change event when mouse is clicked outside a panel

    Hi i am trying to work out the event that handles when i click outside a area "i guess that is how to put it"

    This is exactly what i mean

    I have a panel i.e
    Code:
    ProfileNamePanel
    and a text box i.e

    Code:
    Profile_NameTextBox
    I whish for the ProfileNamePanel to change color when i click inside the Profile_NameTextBox which i obviously done using

    Code:
        Private Sub Profile_NameTextBox_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Profile_NameTextBox.MouseClick
    
    
            ProfileNamePanel.BackColor = Color.Aquamarine
    
        End Sub
    BUT now i am stuck trying to work out what event handles changing the color again say to black once i have clicked away from

    Profile_NameTextBox


    So in short i whish to change a panels color when i click on a textbox then after i finish that textbox and click elsewhere i want to change the color of the panel again.

    Cheers in advance

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

    Re: change event when mouse is clicked outside a panel

    the form, textbox, + panel all have a _MouseClick event of their own.
    also you can use 1 event to handle multiple control's events:

    Code:
    Private Sub multiple_controls__MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseClick, Me.MouseClick
    
    End Sub

  3. #3
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: change event when mouse is clicked outside a panel

    The best place to put your code is the GotFocus and LostFocus events of Profile_NameTextBox, by this way you don't have to put the code in the MouseClick event of all other controls.

    Code:
        
        Private Sub Profile_NameTextBox_GotFocus(sender As Object, e As EventArgs) Handles Profile_NameTextBox.GotFocus
            ProfileNamePanel.BackColor = Color.Aquamarine
        End Sub
    
        Private Sub Profile_NameTextBox_LostFocus(sender As Object, e As EventArgs) Handles Profile_NameTextBox.LostFocus
            ProfileNamePanel.BackColor = Color.Black
        End Sub



  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2013
    Location
    Newcastle, Australia
    Posts
    158

    Re: change event when mouse is clicked outside a panel

    Thanks guys very helpfull

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