Topmost form without focus

theScien

Member
Joined
Jun 14, 2005
Messages
7
Location
London, UK
Programming Experience
10+
Hi, I'm having a bit of a problem with the following;

I want to have a form that will be topmost, so always on top, I have this form with an opacity of 50% and maximised, but I want to be able to access all applications under it, so I can work on this applications.

The idea is to have this on my laptop, which lacks proper brightness control, so when I'm working at night in bed, next to my girlfriend, the brightness coming from the LCD is minimal.

How can I achieve this?

I have tried a few things, but none work, because the form is on top you will not have access to anything under it, which I understand, but there must a way.

Anyone?
 
What if you maximized a topmost form with Opacy set to less that 100% and during mousemove/timer set the region to be everything except just enough to let mouse pointer through to the window under?

Here the code I used, I had to remove the form Text and disable ControlBox also for the point to get right, also I needed to add a button to enable close of the overlay form and this buttons rectangle had to be excluded from the region that was excluded..
VB.NET:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim r As New Region(New Rectangle(Me.Location, Me.Size))
    Dim pt As Point = Me.PointToClient(Windows.Forms.Cursor.Position)
    pt.Offset(-1, -1)
    Dim rct As New Rectangle(pt, New Size(20, 20))
    Dim r2 As New Region(rct)
    r2.Exclude(Button1.ClientRectangle)
    r.Exclude(r2)
    Me.Region = r
    r.Dispose()
End Sub
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.Close()
End Sub
It didn't work for menues and windows startmenu that are more topmost. Try it out and see if it can be done better or otherwise.

BTW, the screen filter idea of VIS781 is good and cheap solution!
 
Thanks for all the answers, I think what I need is just these two lines on formLoad;

VB.NET:
SetWindowLong(Me.Handle, GWL.ExStyle, WS_EX.Layered Or WS_EX.Transparent)
 
SetLayeredWindowAttributes(Me.Handle, 0, 255 * (MySliderControl.Value / 100), LWA.Alpha)

However I can't test it yet as my VisualStudio .NET 2003 is misbahaving on my desktop since I installed .NET Framework 2.0, may need to get VS 2005, so I will test this later on my laptop.

My transparent form will not cover the taskbar (still have to find a way to know the taskbar height and calculate accordingly) so the application can be unloaded.

No screen filter, they shine too much, are bulky and get in the way, besides .NET allows it so lets have it :)

Will let you know more later.

Thanks once again.
 
My transparent form will not cover the taskbar (still have to find a way to know the taskbar height and calculate accordingly) so the application can be unloaded.

You can get the height of the Task Bar using the following...

VB.NET:
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, 
ByVal lpWindowName As String) As Intptr
 
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As IntPtr, 
ByRef lpRect As RECT) As Int32
 
<StructLayout(LayoutKind.Sequential)> _ 
Private Structure RECT
 Public Left As Int32
 Public Top As Int32
 Public Right As Int32
 Public Bottom As Int32
End Structure
 
 
Dim TrayHandle as IntPtr = FindWindow("Shell_traywnd", "")
Dim Rct as RECT
GetWindowRect(TrayHandle , Rct)
Dim TaskBarHeight as Integer = Rct.bottom - Rct.top.
 
A maximized form will not cover taskbar, so I don't see how that could be an issue. As for closing the app, the same goes for Hotkeys, you don't need them for this, but hotkeys give you option to control other functions of the form when you can't click it directly.
 
Oh, true, I missed that when doing my small tests... :eek:
 
Ok, its all almost working, I decided to go for a TrayIcon as that saves space in the main taskbar area.

As for the (vis781) code to get the taskbar height, it didn't work, where should I put that code? I tried everywhere, in the main form, on my startup module, as a class, just couldnt get it to work.

I have noticed, that altough it works as expected, the context menus and tooltips of other applications still have full brightness, so my software filter is not affecting those, also the start buttom menu, but I guess I can live with that.

Also how can I set the opacity of [frmApplication] from [frmConfig] in real time so I can see how much is being applied?
I tried this is [frmConfig] a form that opens on top;

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] trbOpacity_Scroll([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] trbOpacity.Scroll[/SIZE]
[SIZE=2][COLOR=#008000]'[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]frmApplication.Opacity = trbOpacity.Value / 100[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
But frmApplication.Opacity is underlined saying it requires an object reference??? I understand it, but how to set the reference?

Also on the context menu to open the [frmConfig] when clicked I cant just say;

VB.NET:
[SIZE=2]frmConfig.ShowDialog()[/SIZE]
It has to be;

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] frmConfig [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] frmConfig[/SIZE]
[SIZE=2]frmConfig .ShowDialog()[/SIZE]
But doesnt this create a new instance of the form? The form has already been created, I just want to show it but calling from another form.

Its almost done, I will send you the utility when its finished.
 
Last edited:
I told you about the menus before.. they are more topmost.

Your form dialog questions really belong in its own thread as it has nothing to do with transparency/click-through form. Read the three-part multiple forms tutorials here http://www.devcity.net/Articles/94/1/multipleforms.aspx and start new threads if you wonder about different topics.
 
Back
Top