Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Window form size/localtion problem

Status
Not open for further replies.

Salte2

Programmer
Nov 5, 2004
17
0
0
NO
I want to place a button in the lower right hand corner of my Windows Form, and i want my form to be maximized. How should i go about this? Currently my code looks like this:
Code:
public MyForm()
{
this.WindowState = FormWindowState.Maximized;
<initialize button 'myButton'>
this.myButton.Location = new System.Drawing.Point(this.Width - 150, this.Height - 150);
}

But for some reason the button is placed somewhere in the upper left hand quarter of the window? It seems like even tho' i maximize the window the size attributes (like Width) doesnt change, and i dont even know what these are, as i havnt set them explicitly. Any suggestions?
 
Have you tried getting the width of the window rectangle?, and then explicitly placing the button at the Bottom RHS of that rectangle?

If the window is drawn Maximised, then the width and height will be changed.

Try adding some text to the window displaying this.window.width, and this.window.height, adn then playing about with the window edge to see how it changes.

K
 
Thanks for your help Kalisto, but I'm not sure what you mean i'm afraid.

After the window is maximized I would think the "this.Height" and "this.Width" values would change, but they dont, they stay at 300 (dont know where that number comes from). I dont want to set these values explicitly (because i dont know the size/resolution of the users screen).

So how can i get values for height and widht after the window has been maximized?

Have you tried getting the width of the window rectangle? How would i do this?
 
I'll have a look in a while, I need to run up my c# compiler (Im not going to be at my desk for about 3 hours Im afraid.)

Unless there is some sort of autoscale property (forgive me, I usually work in c++, not c#), I would expect the window rectangle to change with the size of the window, not remain fixed.

What happens if you start the form off maximised, rather than it appearing as a pop-up sized window?

Have you tried getting the width of the window rectangle? How would i do this?
-> I assume you have visual studio?

In your code somewhere, put a break point (After the window has been max'd, but in code that refers to your form). When your program stops at the breakpoint, have a look at this.Width, and this.Height, see what they are.

Let me know if you fix it, else I'll have a look later, when I get back to my desk.

K
 
I'm not sure if this helps, but here is a way to maximize a users screen. If you look inside the new Size(), that is how I get the height and width.

Code:
//make screen full length of users working area
this.Size = new Size(Screen.GetWorkingArea(this).Width, Screen.GetWorkingArea(this).Height);

this.CenterToScreen();

Erica
 
that solved my problem ecanizzo, thanks a lot! Thanks to you too Kalisto!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top