Setting the Screen Location of Windows Forms

G

G Uljee

Hi all,



I've some difficulties with the screen/form locations.

When I fist set my location of the form and then the execute the show
command the form is located at "WindowsDefaultLocation".

Based on that I've created the following procedure:



/// <summary>

/// Set the specified window's size and location.

/// The size is only adjusted if both the width and
height are > 0

/// </summary>

public void Set(System.Windows.Forms.Form form)

{

if(form != null)

{

if(m_visible)

{

form.Show();

form.Refresh();

}

if(m_width>0 && m_height>0)

form.Size = new
Size(m_width, m_height);

form.Location = new
Point(m_X, m_Y);

form.Refresh();

}

}



But now you're able to see that the location will be changed.

What can I do about this?



Thanks in advance,

Gaby
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

I may not getting you right, but you can change the FormStartPosition
property value to "Manual" and then set the values of the Size and Location
properties in code or in the designer. Then, when you invoke the Show()
method, the form will be displayed in the specified position and will have
the requested bounds.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top