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

VS 2012 Form always "on desktop" ; changing form from "on desktop" to topmost and back

$
0
0
Hello,

I've got the following situation:

My program consists currently of two forms: Blue and red. I want both of those to be "on the desktop" aka every other program should be on a higher toplevel than my forms. The blue form should ALWAYS be at the very bottom, the red form should also be at the bottom but should be able to move up/down.
Name:  1.jpg
Views: 61
Size:  7.5 KB

If I start any app it will obviously be on top of mine.
Name:  2.jpg
Views: 57
Size:  9.8 KB

Now.. if I move my mouse all over to the right border of the screen I want the red form to be topmost, and if I leave the red-form-area I want it to be on the desktop and the other app beeing on top of it again. (Same should happen with a fullscreen app, picture two)

Name:  3.jpg
Views: 36
Size:  9.9 KB Name:  4.jpg
Views: 25
Size:  5.1 KB

I've used search but it only brings up pretty old topics which solutions that did party/not work for me.
So far I have:

Blue form: 1520x1050, Top 0, Left 0
Red form: 400x1050, Top 0, left 1520
Timer1 on blue form (Enabled, Interval 10)
Label1 on blue form

Code:

 
    Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As IntPtr, _
    ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, _
    ByVal Y As Integer, ByVal cx As Integer, ByVal cy As _
    Integer, ByVal uFlags As UInt32) As Boolean

    ReadOnly HWND_BOTTOM As New IntPtr(1)
    ReadOnly HWND_TOP As New IntPtr(0)

    Private Const SWP_NOSIZE As UInt32 = &H1
    Private Const SWP_NOMOVE As UInt32 = &H2

Private Sub form_blue_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        form_red.Show()
        Me.Top = 0
        Me.Left = 0
End Sub

Private Sub form_red_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Top = 0
Me.Left = 0
End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Label1.Text = MousePosition.X & " / " & MousePosition.Y
        If MousePosition.X = 1919 Then
            form_red.TopMost = True
            Dim flags As UInt32 = SWP_NOMOVE Or SWP_NOSIZE
            SetWindowPos(form_red.Handle, HWND_TOP, 0, 0, 0, 0, flags)
        ElseIf MousePosition.X < 1519 Then
            form_red.TopMost = False
            Dim flags As UInt32 = SWP_NOMOVE Or SWP_NOSIZE
            SetWindowPos(form_red.Handle, HWND_BOTTOM, 0, 0, 0, 0, flags)
        End If
    End Sub


1. If I run it, then click for example my fullscreen chrome and then move to the right border, nothing will happen.

2. If I run it, then click for example my fullscreen chrome, click on my form_blue in the taskbar (this will not show anything of my app, chrome is still fullscreen on top) and then move to the right border, red form will show up, and disappear when I leave it. Works
2.1 If I click any other app and mine loses focus, it will do nothing again

3. I didn't do anything with the blue form and as a result it's not on the bottom. If I put blue AND red form on bottom (If X < 1519) then it will show red form and put both red and blue above my other programs as I'm leaving the area.

I'd appreciate any ideas.
Attached Images
    

Viewing all articles
Browse latest Browse all 27353

Trending Articles



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