954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to setBounds in percentage of screen size?

Hi,
How can I setBounds of a component in percentage of screen size so that the interface looks same on different resolutions.
I am using Visual Studio 2008. When I click on a button in designer view it shows me button's properties on right side. There I can set Location (x and y) of the button. But it allows me to enter only numbers. I want to add some formula like:
For x: SystemInformation.PrimaryMonitorSize.Width / 2;
For Y: SystemInformation.PrimaryMonitorSize.Height / 2;

Could anyone please help me fix this ??

adi.shoukat
Newbie Poster
23 posts since Sep 2009
Reputation Points: -5
Solved Threads: 0
 

You can set a control's location and many other properties from within the code. What you want to do would be done like so, and other properties can be set in a similar way.

ButtonName.Location = new Point(X, Y);

I'd put this in the constructor, after InitializeComponent();, so that it runs when the program is started.

WildBamaBoy
Junior Poster
181 posts since May 2010
Reputation Points: 33
Solved Threads: 13
 

WildBamaBoy,
Thanks for your suggestion. Yes I am doing this right now, but it's really hectic to set location of each component manually. I thing it nullifies the convenience of drag-drop thing provided by Visual Studio. What do you think?
I was expecting some way that we drag a component on form in design time and the component automatically adjusts it's location according to screen width and height.


Adil Shoukat

adi.shoukat
Newbie Poster
23 posts since Sep 2009
Reputation Points: -5
Solved Threads: 0
 

why dont you use Docking and Anchoring properties..???

this will get you going: http://www.codeproject.com/KB/miscctrl/anchordock.aspx

sandeepparekh9
Posting Whiz
367 posts since Dec 2010
Reputation Points: 123
Solved Threads: 71
 

why dont you use Docking and Anchoring properties..???

this will get you going: http://www.codeproject.com/KB/miscctrl/anchordock.aspx

Thanks for help. Anchor property seems to be doing what I wanted. Resizing is very smooth now. I've set the Anchor property of a button to 'Top'. Will it be positioned on same relative location on different sizes of screens ??

adi.shoukat
Newbie Poster
23 posts since Sep 2009
Reputation Points: -5
Solved Threads: 0
 

yes it does the same.... anchor your control to right and top corner.... or top and left corner

gulbano
Posting Whiz
336 posts since Apr 2011
Reputation Points: 11
Solved Threads: 2
 
yes it does the same.... anchor your control to right and top corner.... or top and left corner


Awesome ..
It worked :)
Thanks everyone for help

adi.shoukat
Newbie Poster
23 posts since Sep 2009
Reputation Points: -5
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: