-1

I have a winform (c#, let's say 250px by 250px) that needs to stay in one location on the screen regardless of screen resolution i.e 800x600, 1920x1080 etc. The Winform itself contains only one element - a picturebox so what's inside really doesn't matter (no need to worry about fonts, etc.). I just need it to stick in one place on the screen from one monitor to another.

Any ideas? Thanks in advance.

Zuzlx
  • 1,246
  • 14
  • 33
  • Care to comment for -1? – Zuzlx May 07 '15 at 22:44
  • Do you want it to appear always on the same location after application start? Or do you want it to stay there, so that you cannot move the window? – azt May 07 '15 at 22:45
  • https://msdn.microsoft.com/en-us/library/system.windows.forms.form.startposition(v=vs.110).aspx – Steve May 07 '15 at 22:46
  • @azt I know how to fix it's location on start up by setting pixels. But that has to change when the resolution changes...no? – Zuzlx May 07 '15 at 22:46
  • @steve thanks but as far as I can tell your reference doesn't apply to the question at hand. I need it to be on a fix location on top of an image. – Zuzlx May 07 '15 at 22:53
  • Form.StartPosition = Manual, then set the Location property with the coordinates where do you want your form to appear – Steve May 07 '15 at 22:57
  • So your desired position is a function of the screen size, e.g. 20% of screen with from left and 30% of screen height from top? – azt May 07 '15 at 22:58
  • @azt yes. % would work. Can I give `location` percentage? – Zuzlx May 07 '15 at 23:13

2 Answers2

0

Could you use one of these? 1) WindowsState = Maximized (then you dont worry, it always takes whole screen) 2) StartPosition = CenterScreen (then it always shows as centered), or CenterParent to center within parent form 3) Location = in this case you would have to do some math to get screen size, your form size than based on that center it but I dont see point of using this considering that StartPosition does it already for you. Hope that helps

pixel
  • 9,653
  • 16
  • 82
  • 149
  • 1
    Thanks. I'm not trying to center it. It has to be fixed on top of and image in some x,y coordinates – Zuzlx May 07 '15 at 22:50
0

Ok, so in order to get the window at a fixed location given in % of the screen size, you need the screen size (e.g. using this answer), compute the desired position, and set it as the window-location. Since you need to do it at startup, you could do it before you show the window, or maybe best inside a Frame.Loaded event handler.

Community
  • 1
  • 1
azt
  • 2,100
  • 16
  • 25