Solved

How can I anchor a windows form?

Posted on 2004-04-07
9
219 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
Comment Utility
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
Comment Utility
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
Comment Utility
Right. I thinked he wants form in the center.
0
 

Author Comment

by:mpozzan
Comment Utility
I do want the form on the right of the screen
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 20

Accepted Solution

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

Expert Comment

by:TheAvenger
Comment Utility
Upps, a little bit unfair to Alex
0
 

Author Comment

by:mpozzan
Comment Utility
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
Comment Utility
You should set the start position of the form to Manual
0
 

Author Comment

by:mpozzan
Comment Utility
sounds good. thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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