By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

relative position in different resolutions

P: 36
How can i get relative position in different resolutions using c# ??
Jan 31 '09 #1
Share this Question
Share on Google+
9 Replies

Expert 100+
P: 229
You can read this link for automatic scaling:

If you want to have your controls positioned and resized dynamically as you resize the parent form, then it is a different thing, because that is not related to the screen resolution, but rather the size of the parent form.

In that case you should use layout panels, and anchor your controls to their container panels. You can achieve relative positioning using FlowLayoutPanel or TableLayoutPanel. Also, by using any control's Anchor property, you can anchor control's sides (top/bottom/left/right) to a parent control, to make it resize together with the parent control.

Check this link for an example of using the TableLayoutPanel:
Jan 31 '09 #2

P: 36
Thanks for your advice , but i need to Know how to get relative position in different resolutions using c# ? Do you have any idea ??
Feb 1 '09 #3

Expert 100+
P: 229
If you want to get the screen resolution programmatically, you can use:

Expand|Select|Wrap|Line Numbers
  1. System.Drawing.Rectangle resolution = Screen.GetWorkingArea(someForm);
where 'someForm' is a form that is located on the display you are interested in (don't forget the possibility of multiple displays).

But it would help if you would describe in detail what you are trying to accomplish.
Feb 2 '09 #4

P: 36
This is the problem

I have Form display in Full Screen Mode; I used Scale Method built in .Net to Scale all controls in the form at the Form Load

SizeF MaximizeScalFactor = new SizeF((float) Screen.PrimaryScreen.Bounds.Width / 800, (float) Screen.PrimaryScreen.Bounds.Height / 600);
All controls used at form (button ,richtextbox,listbox,label) was Scale correctly expect FlashControl it was Scale but it's position changed . So I try to calculate all relative position depend on the screen resolution.
Feb 2 '09 #5

P: 36
What about PointToScreen & PointToClient??? Is it useful in case of getting relative position in different resolutions?
Feb 3 '09 #6

Expert 100+
P: 229
No, they are not related to screen resolution. They simply convert point coordinates between your client control and screen (by translating them).

For example, if you have a panel inside a form, and then a text box inside that panel, text box location will be relative to the top-left point of the parent panel ("client coordinates"). Panel location will be relative to the top-left origin of the parent form. Using PointToScreen you would be able to convert all those points into a single coordinate system (relative to the screen top-left corner).
Feb 3 '09 #7

P: 36
OK, but this code not gives me relation position? Its only get screen resolution.
1. System.Drawing.Rectangle resolution = Screen.GetWorkingArea(someForm);
If I have point (479, 9) at screen resolution 1024,786
IS this Equation true to get this point at another resolution?
(472*Newresoluation.x, 9* Newresoluation.y) or NO??
Feb 3 '09 #8

Expert 100+
P: 229
So, if your x coordinate is 400px in 800x600 resolution, and you want it to be 512px in 1024x768 resolution, then the way to get the new coordinate is obviously:

a) 400px / 800px = 1/2
b) 1/2 * 1024px = 512px

So, first divide with the old resolution, and then multiply with new resolution.
Feb 3 '09 #9

P: 36
and applay this to Y coordinate also to have point in new resoluation .

i mean the answer of my question
How can i get relative position in different resolutions using c# ??

By this equation :

a) Old point.x / OldResoluation.x = R

b) R * newResoluation.x = relativeXposition

and so on for Y .

if Yes , Thanx aloooot :)
Feb 3 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.