Me.Focus()

  • Thread starter Thread starter Matthew
  • Start date Start date
M

Matthew

I have a taskbar icon in my application. When the user double-clicks it I
would like it to give focus to a form that is already open, but is behind
other windows unrelated to my program.

Is this possible?

I tried Me.Focus() but that didn't seem to do anything.

Matthew
 
I have a taskbar icon in my application. When the user double-clicks it I
would like it to give focus to a form that is already open, but is behind
other windows unrelated to my program.

Is this possible?

I tried Me.Focus() but that didn't seem to do anything.

Matthew

Try Me.BringToFront() : Me.Focus()

// CHRIS
 
Matthew said:
I have a taskbar icon in my application. When the user
double-clicks it I would like it to give focus to a form
that is already open, but is behind other windows unrelated
to my program.

Is this possible?

AFAIK, you will need p/invoke on 'AttachThreadInput' + 'SetForegroundWindow'
to archieve what you want.
 
Thanks for the response.
Try Me.BringToFront() : Me.Focus()

I gave it a shot, and it didn't work in my application. Just for fun, I
created a new Solution, added a new NotifyIcon, and added this code to the
form:

Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
Me.BringToFront() : Me.Focus()
End Sub

That didn't work either.

Matthew
 
AFAIK, you will need p/invoke on 'AttachThreadInput' +
'SetForegroundWindow' to archieve what you want.

Bingo!
My final code:

Imports System.Runtime.InteropServices
'Windows Form Designer generated code
<DllImport("user32.dll")> _
Public Function SetForegroundWindow(ByVal hwnd As IntPtr) As Boolean
End Function
Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
SetForegroundWindow(Me.Handle)
End Sub

Matthew
 
Me.Activate()

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 
Back
Top