[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

How can I anchor a windows form?

I’m looking at different ways of anchoring a custom shaped windows form to the right side of the screen. As well, the form should fill the height of the screen but be approximately 230 pixels across.
Can someone give me some code that would auto-stretch the window to the height of the screen, but still be able to define the width?
0
mpozzan
Asked:
mpozzan
  • 4
  • 3
  • 2
1 Solution
 
AlexFMCommented:
Do you mean this?

        private void Form1_Load(object sender, System.EventArgs e)
        {
            int nWidth = 230;

            this.Top = 0;
            this.Height = SystemInformation.PrimaryMonitorSize.Height;

            this.Left = (SystemInformation.PrimaryMonitorSize.Width - nWidth)/2;
            this.Width = nWidth;
        }
0
 
TheAvengerCommented:
Just a remark to the post of Alex:

instead
this.Left = (SystemInformation.PrimaryMonitorSize.Width - nWidth)/2;

use

this.Left = SystemInformation.PrimaryMonitorSize.Width - nWidth;
0
 
AlexFMCommented:
Right. I thinked he wants form in the center.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
mpozzanAuthor Commented:
I do want the form on the right of the screen
0
 
TheAvengerCommented:
Well, the code above with my correction is for the right of the screen.
0
 
TheAvengerCommented:
Upps, a little bit unfair to Alex
0
 
mpozzanAuthor Commented:
the following code, does not achor the windows form to the right side of the screen.
As well, it appears in the centre of the screen
private void Form1_Load(object sender, System.EventArgs e)
        {
            int nWidth = 230;

            this.Top = 0;
            this.Height = SystemInformation.PrimaryMonitorSize.Height;

            this.Left = SystemInformation.PrimaryMonitorSize.Width - nWidth;
            this.Width = nWidth;
        }
0
 
TheAvengerCommented:
You should set the start position of the form to Manual
0
 
mpozzanAuthor Commented:
sounds good. thanks
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now