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 ??

7 Years
Discussion Span
Last Post by adi.shoukat

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.


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


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 ??


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

Votes + Comments
really helpful

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.