Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Activate form 1

Status
Not open for further replies.

mwa

Programmer
Jul 12, 2002
507
US
I have a little Task entry application that I wrote for me and my colleagues to track completed tasks throughout the day. The application stays positioned at the top of the screen and has it's height=30px and opacity=25%. When the user mouses over the form, it expands and opacity changes to 100%:
Code:
Private Sub Form1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseHover
        Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width
            Me.Width = 260
            Me.Height = 140
            Me.Left = (intX / 2) - (Me.Width / 2)
            Me.Top = 0
            Me.Opacity = 1
            Me.Activate()
    End Sub

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        txtActivity.Focus()
    End Sub

The problem that I have, is that if you're using another application (say IE for example), and then Mouse over the Task app, it expands and sets the focus to txtActivity as expected. However, the prior application remains activated. So if you begin typing (expecting to enter text into txtActivity), the keystrokes are sent to IE window, not the Task application.

Any ideas how to stop this and actually activate the Task form on mouse hover?

mwa
<><
 
From the help text for Control.Focus Method:
Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
Instead, try:
Code:
txtActivity.Select()
 
That did it... Thanks.

mwa
<><
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top