473,396 Members | 1,726 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,396 software developers and data experts.

StartPosition

I have a blank form and my Sub New is as follows:

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

msConnectionString = msConnectionString & ";Workstation ID=" &
Environment.MachineName

BuildForm()

End Sub

In the Build Form sub, I read from the database and get information used to
add controls, change the form size, etc. In the Build Form sub, one of the
options is to change the start position from WindowsDefaultLocation to
either CenterScreen or Manual (and provide the start point).

I have suspened the layout of the form before all of the code in the Build
Form sub and then Resumed it (me.resumelayout(True)).

When the code changes the start position to CenterScreen, the form (at the
end) does not recenter on the screen based upon the new form size. Am I
missing something obvious?

Thank you

Nov 21 '05 #1
2 2136
"Stephen Costanzo" <sx********@hotmail.com> schrieb:
When the code changes the start position to CenterScreen, the form (at the
end) does not recenter on the screen based upon the new form size. Am I
missing something obvious?


Are you setting the form's size before setting the start position?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
Yes I am.

So the flow again is:

Public Sub New()

MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
msConnectionString = msConnectionString & ";Workstation ID=" & Environment.MachineName
BuildForm()
End Sub

....

Public Sub BuildForm()
....
Me.SuspendLayout()
....
Me.Width = miMaxWidth + miControlGap * 2 + panPosition.Width
Me.Height = iY + miBaseControlHeight * 4 + panCommandPanel.Height
Me.StartPosition = FormStartPosition.CenterScreen
....
Me.Refresh
Me.ResumeLayout(True)
End Sub

Therefore the functionality in the BuildForm is overriding the functionality in the InitalizeComponent code. The screen is centered based upon the initial size of the form not the current size of the form. Therefore if I made the form 100x100 and the size turned out to be 400x380 it is centered as if it were the original.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message news:OW*************@TK2MSFTNGP11.phx.gbl...
"Stephen Costanzo" <sx********@hotmail.com> schrieb:
When the code changes the start position to CenterScreen, the form (at the
end) does not recenter on the screen based upon the new form size. Am I
missing something obvious?


Are you setting the form's size before setting the start position?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

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

Similar topics

0
by: C-Sharper or C-Hasher, one of the two | last post by:
Hi Guys and Gals, I have a small, two form, application. Form1 is the main window and Form2 is a small window that has a label and a progress bar on it. I wish to display form2 whilst doing some...
1
by: DotNetMania | last post by:
How do you specify the startPosition of common dialog boxes in C#? such as OpenFileDialog there is not Position or Location method.... best regards... charles
3
by: cider123 | last post by:
Everything I've read so far states you can't inherit or extend these dialogs because they're "sealed". I considered building my own custom control, but I haven't been able to find: 1) How to...
1
by: Richard Loupatty | last post by:
Does anyone know how to control windows mediaplayer? I would like to give the user the possibility to skip in the player by setting a new startposition. tia Richard
5
by: Howard | last post by:
how can i make a program that always start at the top left corner of the screen in c#? vs does seem to have that option
3
by: sklett | last post by:
I thought this would be easy. I want to position a login form based on whether or not it has a parent form, so I tried this: <code> if (ParentForm == null) { StartPosition =...
3
by: smellican | last post by:
Is there an easy way to set the starting position of a common dialog such as savefiledialog, printdialog, fontdialog, etc.? There doesn't seem to be a StartPosition property for common dialogs.
2
by: Phillip Ross Taylor | last post by:
I have configured a few of the windows I am working on to have the form value "Start Position" to be "CenterParent" but some of them don't. Does Center Parent only work when the dialog is modal?...
6
by: Eric B. | last post by:
I posted about this before but it is still bugging me. I am creating an instance of form2 from my form1, and although I have the StartPosition set to CenterParent for the form2 it is not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.