Setting TopMost
Setting TopMost
Setting TopMost
Setting TopMost
Setting TopMost
Setting TopMost Setting TopMost Setting TopMost Setting TopMost Setting TopMost Setting TopMost Setting TopMost Setting TopMost
Setting TopMost Setting TopMost
Setting TopMost
Go Back  Xtreme Visual Basic Talk > > > Setting TopMost


Reply
 
Thread Tools Display Modes
  #1  
Old 10-10-2014, 02:49 PM
JeremyBenson11 JeremyBenson11 is offline
Regular
 
Join Date: Dec 2013
Posts: 50
Default Setting TopMost


Hey,

I'm trying to figure out how to set the topmost property on MainWindow. I know accessing it directly wont work

Code:
MainWindow.TopMost = true
Is there another way of doing it? Here's my simple subs. Init called on window loaded the other on the click of at menu button.

Code:
    Public Sub init_software()

        spellChecker = True
        float = True
        output.SpellCheck.IsEnabled = spellChecker


    End Sub
Code:
  Public Sub toggle_float()

        If float Then

            float = False


        Else

            float = True

        End If

    End Sub
Reply With Quote
  #2  
Old 10-10-2014, 02:51 PM
JeremyBenson11 JeremyBenson11 is offline
Regular
 
Join Date: Dec 2013
Posts: 50
Default

lol, I know the code it redundant with the booleans, I'll take em out, but still...
Reply With Quote
  #3  
Old 10-11-2014, 05:10 AM
passel's Avatar
passelSetting TopMost passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

I'm not sure I understand.
What is MainWindow?
If the code is in your form, you could always reference yourself.
Me.TopMost = True

If you want to toggle a boolean you can just set it to the opposite of itself.
Me.TopMost = Not Me.TopMost

Quick Example. We could set Me.TopMost = True here, but used the toggle syntax just to show that it works. This will display some Text in large Red letters.
If you click and drag with the left mouse button on any letter you can move the text (i.e. moving the Form, which is may or may not be topmost depending on odd or even activations).
If you click on a letter with the right mouse button, it will close the form.
Code:
Public Class Form1

  Private Sub Form1_Activated(sender As Object, e As System.EventArgs) Handles Me.Activated
    Me.TopMost = Not Me.TopMost
  End Sub

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Bounds = New Rectangle(0, 0, 1600, 160) 'Screen.PrimaryScreen.WorkingArea
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    Me.TransparencyKey = SystemColors.Control
  End Sub

  Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    Static l As Point
    If e.Button = Windows.Forms.MouseButtons.Left Then
      Left += e.X - l.X
      Top += e.Y - l.Y
    Else
      l = e.Location
    End If
  End Sub

  Private Sub Form1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
    If e.Button = Windows.Forms.MouseButtons.Right Then
      Me.Close()
    End If
  End Sub

  Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    e.Graphics.DrawString("Left Button Drags, Right Button exits", New Font(Me.Font.Name, 50), Brushes.Red, 0, 0)
  End Sub

End Class
Each time you click on the form (after clicking on some other window, i.e. each time the form is activated) it will toggle its topmost state.
You can verify that by trying to drag another window over the letters.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 10-11-2014 at 05:38 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Setting TopMost
Setting TopMost
Setting TopMost Setting TopMost
Setting TopMost
Setting TopMost
Setting TopMost Setting TopMost Setting TopMost Setting TopMost Setting TopMost Setting TopMost Setting TopMost
Setting TopMost
Setting TopMost
 
Setting TopMost
Setting TopMost
 
-->