Jump to content

Windows Form TopMost C# [Solved]


JohnOne
 Share

Recommended Posts

I'm having trouble keeping my form on top.

The relevant code below, except it simply does not stay on top, and after a search all I can find as a solution

is importing user32.dll (not tried it) but I'd sooner not have to.

Any pro tips?

EDIT: solved

private void InitializeComponent()
        {
            this.SuspendLayout();
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.Window;
            this.ClientSize = new System.Drawing.Size(231, 164);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Form1";
            this.ShowIcon = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
            this.Text = "";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
            this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
            this.ResumeLayout(false);
            this.TopMost = true;
        }
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I nothing I can think of running with topmost property/attribute.

Just browser.

Unless of course my form (the only one in the project) is a child of visual studio, but I've tried release as well as debug.

Does an app in .net require admin rights to stay on top?

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

hmmm.

seems TopMost means TopMost in more than one sense.

If I move the statement to the top...

this.TopMost = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

...It's all gravy.

Cheers.

Solved.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I don't see that, I was editing the region...

"#region Windows Form Designer generated code"

For the record, I added the Topmost from withing the properties tab in VS first, but it never worked

and that's why I began to fart around in there.

And also to add "FormBorderStyle", as I could not find anywhere in properties to do that.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

VS2010 I'm using.

But I could not find a way to get the border style right, all I found was padding which I set to 0.

I'm not, as you can tell, all that clever with VS so if you have any tips to offer I'd be mighty grateful.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...