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?
mpozzanAsked:
Who is Participating?
 
TheAvengerConnect With a Mentor Commented:
Well, the code above with my correction is for the right of the screen.
0
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
AlexFMCommented:
Right. I thinked he wants form in the center.
0
 
mpozzanAuthor Commented:
I do want the form on 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
All Courses

From novice to tech pro — start learning today.