What would the Visual Basic code be for an Always On Top Option?
To set "always on top," set myForm.TopMost = True
from your menu option. See the Form.TopMost documentation.
To un-set it again, set myForm.TopMost = False
.
To toggle whether the Form
is the TopMost
, simply change the property Form.TopMost
.
For example, to set the Form to be on top, use this:
Form.TopMost = True
To disable TopMost
, use this:
Form.TopMost = False
This is what I used to handle the event if you want it user-driven. You will obviously want to create a checkbox named chkAlwaysOnTop
of course. It can also be easily stored in the user settings to keep it state-aware between instances.
Private Sub chkAlwaysOnTop_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles chkAlwaysOnTop.CheckedChanged
Me.TopMost = chkAlwaysOnTop.Checked
End Sub
You'll want this in your program if you want to save said state for the user:
Private Sub MainActivity_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Settings.AlwaysOnTop = chkAlwaysOnTop.Checked
My.Settings.Save()
End Sub
You'll also want this in your form load:
Me.TopMost = My.Settings.AlwaysOnTop
chkAlwaysOnTop.Checked = My.Settings.AlwaysOnTop
If you're interested in what I used this in, it's here: Rubber Stamp (Includes source code link)