Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27353

How to deactivate the main form

$
0
0
I have a form that cannot activate but when pressing its taskbar button, it got the focus, how can i deactivate it so that the focus goes to the previous focused window.

Try this code for example
1- start new project
2- add Button1
3- paste the following code and run it
Code:

Public Class Form1

    Protected Overrides ReadOnly Property CreateParams() As CreateParams
        Get
            Dim cCP As CreateParams = MyBase.CreateParams
            Const WS_EX_TOPMOST As Integer = &H8
            Const WS_EX_NOACTIVATE As Integer = &H8000000L
            cCP.ExStyle = cCP.ExStyle Or WS_EX_NOACTIVATE Or WS_EX_TOPMOST
            Return cCP
        End Get
    End Property

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        SendKeys.Send("A")
    End Sub
End Class

4- Run Notepad and press Button1 to send the letter A
5- Focus the Form1 by clicking its taskbar button.

Now i want to back the focus to the Notepad (or any previous focused window) when i click on Button1

Viewing all articles
Browse latest Browse all 27353

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>