none
Control focus RRS feed

  • Question

  • Hi

    I am having problems with control focus.  Lets say i have two forms next to each other.  If i have focus set to one of those forms, and then move my mouse over to click a button on the second form, i am finding that i have to click the button twice in order to raise the click event.  The first click obviously gives the second form focus, and the second click actually raises the click button event.

    If you look at Windows Live Messenger for example.  You can click on any of those buttons at any time regardless on whether Messenger has focus or not, and the buttons will activate.  Thats basically what i want in my program.

    I have been getting around this issue by using the MouseEnter event to give the control focus when the mouse enters, but i dont like using this as it looks bad imo when forms keep jumping focus every time the mouse enters. 

     

    Wednesday, June 8, 2011 1:04 AM

Answers

All replies

  • Hi,

    Are you using the MouseEnter event for the Form or the Button?

    Consider using it for the Button if you are not already using MouseEnter for each Button to give the Button focus.



    Regards,

    John

    Click this link to see how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    XNA is coming to VB.Net



    Wednesday, June 8, 2011 1:24 AM
  • Hi John

    I had a toolstrip at the top of my form with buttons.  When the mouse entered the toolstrip i was setting focus to that.

    I have tried what you suggested, but it just really gives me the same result in the end.  Setting focus to individual buttons activates the whole form anyway as the controls are children of the form. Again if i site the Messenger example, there seems to be no visual cues that the form has focus until after you have clicked.  Thats really what im looking for, im trying to avoid using the mouse enter event for this.

    I guess i just need to tell the program to activate the control on click, and then somehow redo the click event for the control?

    Wednesday, June 8, 2011 2:12 AM
  • Aaron,

    Open your Live messenger and open a second form.

    Then see how many processes you see running for that.

    Windows messenger uses in my idea not windows forms.

    Windows forms is not build to use active more forms in one a time. To get focus on a windows forms form you first have to select that.

    It is not for nothing that Microsoft is replacing Windows Forms by WPF

    http://msdn.microsoft.com/en-us/library/ms754130.aspx

    But that is always with Microsoft half the world is screaming that the wont change anything and when they change it completely because the possibilities are over in the old technique the other part start screaming why the could not do the same with the old technique because in their idea that should be easy. 


    Success
    Cor
    Wednesday, June 8, 2011 5:39 AM
  •  

    The functionality im talking about is already available with windows forms.  It is not something new or exculsive to WPF.  My program is a 3D graphics modelling application, that has multiple input dialogs/forms for editing graphical elements on the screen.  AutoCAD or 3dsMax are good examples of instances where what im talking about occurs. 

    Obviously the form you want to work with has to have focus, that has never been in question.  The question is how do you set focus to the form you want and raise the button.clicked event with just one click of the mouse, rather than two clicks and without using the mouse enter event to set the form focus.

     

    Wednesday, June 8, 2011 6:18 AM
  • Hi

    I am having problems with control focus.  Lets say i have two forms next to each other.  If i have focus set to one of those forms, and then move my mouse over to click a button on the second form, i am finding that i have to click the button twice in order to raise the click event.  The first click obviously gives the second form focus, and the second click actually raises the click button event.

    If you look at Windows Live Messenger for example.  You can click on any of those buttons at any time regardless on whether Messenger has focus or not, and the buttons will activate.  Thats basically what i want in my program.

    I have been getting around this issue by using the MouseEnter event to give the control focus when the mouse enters, but i dont like using this as it looks bad imo when forms keep jumping focus every time the mouse enters. 

     

    Hello Aaron_p,

    What you can do and put the mouse enter event of your form and place inside these instructions with regard to the focus and the activation of the form:

    Form1

     Private Sub Form1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.MouseEnter
    
      Me.Focus()
    
      Me.Activate()
    
     End Sub
    
    
    
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
      MessageBox.Show("TEST1")
    
     End Sub
    
    

     

    Form2

     

     Private Sub Form2_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.MouseEnter
    
      Me.Focus()
    
      Me.Activate()
    
     End Sub
    
    
    
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
      MessageBox.Show("TEST")
    
     End Sub
    
    

     

    Hello


    Carmelo La Monica  http://community.visual-basic.it/carmelolamonica/
    Wednesday, June 8, 2011 6:32 AM
  • Hi Carmelo,

    Thanks for the response.  Unfortunately the method you just suggested is what i have already been doing.  I'll just quote a few lines from my responses above:

    "I have been getting around this issue by using the MouseEnter event to give the control focus when the mouse enters, but i dont like using this as it looks bad imo when forms keep jumping focus every time the mouse enters. "

    "The question is how do you set focus to the form you want and raise the button.clicked event with just one click of the mouse, rather than two clicks and without using the mouse enter event to set the form focus."

    So yeah good idea but not quite what i'm after.  Also i believe you only need to call Me.Activate as that method already gives the form focus. 

    Thank you again for your response.

     

    Wednesday, June 8, 2011 6:51 AM
  • I did not say that it is something exclusive new to WPF. But you write .Net Windows Forms in one sentence like it is Windows, but that is not the case. .Net Windows forms has some effects which are not always wanted therefore I suggested and not more than that to have a look at WPF. I don't even know if it support out of the box multiple forms, I find it a terrible way of using a program, so I never use that. For instance I never drag a window out of my Visual Studio IDE, while that is simply possible. Visual Studio is build on WPF and that behaviour you see everyday in more programs currently.

     

     


    Success
    Cor
    Wednesday, June 8, 2011 7:15 AM
  •  

    Ok i finally found a thread that resolves the exact issue i'm having.  For those interested it can be found here:

    http://social.msdn.microsoft.com/forums/en-us/winforms/thread/8F0F9E5B-61B8-4AED-AD24-3BFC84563AF2

    Bit of an ugly work around, but it works.

    • Marked as answer by AaRoN_P Wednesday, June 8, 2011 7:56 AM
    Wednesday, June 8, 2011 7:56 AM