Solved

How can I anchor a windows form?

Posted on 2004-04-07
9
222 Views
Last Modified: 2010-04-15
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
Comment
Question by:mpozzan
  • 4
  • 3
  • 2
9 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 10780846
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
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10781439
Just a remark to the post of Alex:

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

use

this.Left = SystemInformation.PrimaryMonitorSize.Width - nWidth;
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10781458
Right. I thinked he wants form in the center.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:mpozzan
ID: 10783768
I do want the form on the right of the screen
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 500 total points
ID: 10783783
Well, the code above with my correction is for the right of the screen.
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10784503
Upps, a little bit unfair to Alex
0
 

Author Comment

by:mpozzan
ID: 10784508
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
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10784523
You should set the start position of the form to Manual
0
 

Author Comment

by:mpozzan
ID: 10784530
sounds good. thanks
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now