473,416 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Set Form Location and Size before calling Show method

I am developing an application in .Net C# that needs to restore a
number of tool windows to some previous location and size. The problem
I have is that when I create the form and set the Location and Size
properties before calling the Show method, the form is not created in
the Location that I set. If I call Show first everything works fine but
there is excesive flicker when the Location and Size properties are
set.

I tried calling CreateControl() first but it does not seem to make a
differnce. Is there any way I can move and resize a created form before
showing it?

Nov 17 '05 #1
2 6589
Hi,

I wrote this for LayoutSaver component, this class will raise me event
before Form_Load event and there i can set location and size of dialog.
Before you call MyForm.ShowDialog put 'ReferencedForm reffrm = new
ReferencedForm(MyForm)' and set event handler for BeforeLoadEvent. There you
will set location and size for your form.
Code in vb.net, but i hope it will help you.

--
Public Class ReferencedForm
Inherits NativeWindow

Private Const WM_SHOWWINDOW As Integer = &H18

Private _originalform As Form
Private _ishandleset As Boolean
Private _beforeloadraised As Boolean = False

Public Event BeforeLoadEvent As EventHandler

Sub New(ByVal originalform As Form)
If Not originalform Is Nothing Then
_originalform = originalform
AddHandler _originalform.HandleCreated, AddressOf
Me.OnHandleCreated
AddHandler _originalform.HandleDestroyed, AddressOf
Me.OnHandleDestroyed
End If
End Sub

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_SHOWWINDOW Then
If Not _beforeloadraised Then
RaiseEvent BeforeLoadEvent(Me, New EventArgs)
_beforeloadraised = True
End If

End If

MyBase.WndProc(m)
End Sub

Private Sub OnHandleCreated(ByVal sender As Object, ByVal e As
EventArgs)
AssignHandle(CType(sender, Form).Handle)
End Sub

Private Sub OnHandleDestroyed(ByVal sender As Object, ByVal e As
EventArgs)
_originalform = Nothing
ReleaseHandle()
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

End Class
--

Regards,
Josip Habjan, Croatia
http://www.habjansoftware.com

<ma**@financialzinc.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I am developing an application in .Net C# that needs to restore a
number of tool windows to some previous location and size. The problem
I have is that when I create the form and set the Location and Size
properties before calling the Show method, the form is not created in
the Location that I set. If I call Show first everything works fine but
there is excesive flicker when the Location and Size properties are
set.

I tried calling CreateControl() first but it does not seem to make a
differnce. Is there any way I can move and resize a created form before
showing it?

Nov 17 '05 #2
Set the StartPosition to Manual

viz

Form f = new Form();
f.StartPosition = FormStartPosition.Manual;

Nigel

"ma**@financialzinc.com" wrote:
I am developing an application in .Net C# that needs to restore a
number of tool windows to some previous location and size. The problem
I have is that when I create the form and set the Location and Size
properties before calling the Show method, the form is not created in
the Location that I set. If I call Show first everything works fine but
there is excesive flicker when the Location and Size properties are
set.

I tried calling CreateControl() first but it does not seem to make a
differnce. Is there any way I can move and resize a created form before
showing it?

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pujo Aji | last post by:
I have a problem with an object calling outside method: Forexample in the main part I have an object and the object will do something time independent, and after it is finished working it should ...
2
by: Peter Oliphant | last post by:
I've tried to set up a Form location via its constructor in the following way (My_Form is derived as a child of the standard Form): My_Form( int x, int y, int w, int h ) { Rectangle rect( x,...
1
by: Paul Fairless | last post by:
Could someone please explain how I overload the Show() method of a form? Suppose I select a record from a datagrid on Form1, then I want to show the details of the selected record by opening...
3
by: John Devlon | last post by:
Hi, does anyone know how to change a form loaction ? I tried ... frmTest = new Form frmTest.location = new point (0,0) frmTest.show()
1
by: David Veeneman | last post by:
I'm having a problem getting design-time property binding to work with a form's size and location properties. I started with the Location property under Application Settings in the Properties...
6
by: Rob Cowie | last post by:
Hi all, Is there a simple way to call every method of an object from its __init__()? For example, given the following class, what would I replace the comment line in __init__() with to result...
5
by: Earl | last post by:
I need to call a method on an owned child form, and am wondering if the best way of doing this is to capture the Closing event of the form that passes control back to the form where I have the...
10
by: =?Utf-8?B?QWxiZXJ0IEZ1?= | last post by:
Hi, my function: myAdjustForm.Show(); I am using the Show method to show the pop-up window to the users in my C# program. I found that I have invoke this function TWICE at the beginning...
6
by: Nilam2477 | last post by:
I have wizard kind of windows application with many forms. I have set the form Location this.Location = new Point(100, 100); This works fine with single monitor. If the user connects to multiple...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.