Home All Groups Group Topic Archive Search About
Author
10 Oct 2006 8:16 PM
bwadley
Hi,

Im fairly new to VB.NET and am hoping someone can help me with what is
probably a simple problem.

I have an MDI app, when I open a child form, I want it centered to the
parent.  So I put some code in the FormLoad procedure which works out
the centre of the screen and moves the child appropraitely.

This is pretty much the code I have:

        MdiParent = frmMain
        Me.Top = ((frmMain.Height - Me.Height) / 2)
        Me.Left = ((frmMain.Width - Me.Width) / 2)
        Refresh_VehicleList()

The problem is that when this window opens, you can actually see the
form move. It seems that if i remove the call to refresh_vehiclelist
that the problem isnt as bad, but is still visible. This procedure
makes SQL server calls so tends to pause briefly as it opens the
connection.  Its not a speed issue with the hardware as its a current
Core 2 Duo system.

My question is, is there anyway to hide the form before moving it (I
tried the Hide method but it didnt move) so that the user can not see
the form moving every time they open it?

Many thanks in advance!

Brad.

Author
10 Oct 2006 9:09 PM
rowe_newsgroups
Just put the code under Sub New After the InitializeCompenent call. As
for the answer to the me.hide question, you can just set me.visible =
false.

Thanks,

Seth Rowe


bwad***@gmail.com wrote:
Show quoteHide quote
> Hi,
>
> Im fairly new to VB.NET and am hoping someone can help me with what is
> probably a simple problem.
>
> I have an MDI app, when I open a child form, I want it centered to the
> parent.  So I put some code in the FormLoad procedure which works out
> the centre of the screen and moves the child appropraitely.
>
> This is pretty much the code I have:
>
>         MdiParent = frmMain
>         Me.Top = ((frmMain.Height - Me.Height) / 2)
>         Me.Left = ((frmMain.Width - Me.Width) / 2)
>         Refresh_VehicleList()
>
> The problem is that when this window opens, you can actually see the
> form move. It seems that if i remove the call to refresh_vehiclelist
> that the problem isnt as bad, but is still visible. This procedure
> makes SQL server calls so tends to pause briefly as it opens the
> connection.  Its not a speed issue with the hardware as its a current
> Core 2 Duo system.
>
> My question is, is there anyway to hide the form before moving it (I
> tried the Hide method but it didnt move) so that the user can not see
> the form moving every time they open it?
>
> Many thanks in advance!
>
> Brad.
Author
11 Oct 2006 3:30 AM
bwadley
Hi Seth, thanks for your help, but as i'm fairly new to vb.net, can you
please explain a little further what you mean by putting the code under
"Sub New"  and where the InitializeComponent call is?

I have tried some other suggestions here but it seems unless the form
is visible (not hidden) setting the Top and Left positions have no
effect and the form opens in the top left corner of the MDI Parent.

Thanks!


rowe_newsgroups wrote:
Show quoteHide quote
> Just put the code under Sub New After the InitializeCompenent call. As
> for the answer to the me.hide question, you can just set me.visible =
> false.
>
> Thanks,
>
> Seth Rowe
>
>
> bwad***@gmail.com wrote:
> > Hi,
> >
> > Im fairly new to VB.NET and am hoping someone can help me with what is
> > probably a simple problem.
> >
> > I have an MDI app, when I open a child form, I want it centered to the
> > parent.  So I put some code in the FormLoad procedure which works out
> > the centre of the screen and moves the child appropraitely.
> >
> > This is pretty much the code I have:
> >
> >         MdiParent = frmMain
> >         Me.Top = ((frmMain.Height - Me.Height) / 2)
> >         Me.Left = ((frmMain.Width - Me.Width) / 2)
> >         Refresh_VehicleList()
> >
> > The problem is that when this window opens, you can actually see the
> > form move. It seems that if i remove the call to refresh_vehiclelist
> > that the problem isnt as bad, but is still visible. This procedure
> > makes SQL server calls so tends to pause briefly as it opens the
> > connection.  Its not a speed issue with the hardware as its a current
> > Core 2 Duo system.
> >
> > My question is, is there anyway to hide the form before moving it (I
> > tried the Hide method but it didnt move) so that the user can not see
> > the form moving every time they open it?
> >
> > Many thanks in advance!
> >
> > Brad.
Author
11 Oct 2006 11:28 AM
rowe_newsgroups
Sub New() is the construnctor for for an object - in this case the
form. If you type in "Sub New" and press enter the ide will change that
to the following:

    Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

The InitializeComponent is a method that contains the code generated by
the designer. Any time you add a control or change it's properties it
is writen to this method. Generally, you want this call to occur before
anything else happens, that why I (and the comment line in the sub)
tell you to place the code after this call. Unfortunately, mdichildren
apperantly ignore changes to the size properties here also, so my
advice won't help. I'll do some research to find out why, or perhaps
someone else will shed some light on this.

Thanks,

Seth Rowe


bwad***@gmail.com wrote:
Show quoteHide quote
> Hi Seth, thanks for your help, but as i'm fairly new to vb.net, can you
> please explain a little further what you mean by putting the code under
> "Sub New"  and where the InitializeComponent call is?
>
> I have tried some other suggestions here but it seems unless the form
> is visible (not hidden) setting the Top and Left positions have no
> effect and the form opens in the top left corner of the MDI Parent.
>
> Thanks!
>
>
> rowe_newsgroups wrote:
> > Just put the code under Sub New After the InitializeCompenent call. As
> > for the answer to the me.hide question, you can just set me.visible =
> > false.
> >
> > Thanks,
> >
> > Seth Rowe
> >
> >
> > bwad***@gmail.com wrote:
> > > Hi,
> > >
> > > Im fairly new to VB.NET and am hoping someone can help me with what is
> > > probably a simple problem.
> > >
> > > I have an MDI app, when I open a child form, I want it centered to the
> > > parent.  So I put some code in the FormLoad procedure which works out
> > > the centre of the screen and moves the child appropraitely.
> > >
> > > This is pretty much the code I have:
> > >
> > >         MdiParent = frmMain
> > >         Me.Top = ((frmMain.Height - Me.Height) / 2)
> > >         Me.Left = ((frmMain.Width - Me.Width) / 2)
> > >         Refresh_VehicleList()
> > >
> > > The problem is that when this window opens, you can actually see the
> > > form move. It seems that if i remove the call to refresh_vehiclelist
> > > that the problem isnt as bad, but is still visible. This procedure
> > > makes SQL server calls so tends to pause briefly as it opens the
> > > connection.  Its not a speed issue with the hardware as its a current
> > > Core 2 Duo system.
> > >
> > > My question is, is there anyway to hide the form before moving it (I
> > > tried the Hide method but it didnt move) so that the user can not see
> > > the form moving every time they open it?
> > >
> > > Many thanks in advance!
> > >
> > > Brad.
Author
11 Oct 2006 4:07 PM
bwadley
Thanks Seth for explaining that, I understand now. Shame it is still
ignoring the properties.  Appreciate any thing you come up with.

rowe_newsgroups wrote:
Show quoteHide quote
> Sub New() is the construnctor for for an object - in this case the
> form. If you type in "Sub New" and press enter the ide will change that
> to the following:
>
>     Sub New()
>
>         ' This call is required by the Windows Form Designer.
>         InitializeComponent()
>
>         ' Add any initialization after the InitializeComponent() call.
>
>     End Sub
>
> The InitializeComponent is a method that contains the code generated by
> the designer. Any time you add a control or change it's properties it
> is writen to this method. Generally, you want this call to occur before
> anything else happens, that why I (and the comment line in the sub)
> tell you to place the code after this call. Unfortunately, mdichildren
> apperantly ignore changes to the size properties here also, so my
> advice won't help. I'll do some research to find out why, or perhaps
> someone else will shed some light on this.
>
> Thanks,
>
> Seth Rowe
>
>
> bwad***@gmail.com wrote:
> > Hi Seth, thanks for your help, but as i'm fairly new to vb.net, can you
> > please explain a little further what you mean by putting the code under
> > "Sub New"  and where the InitializeComponent call is?
> >
> > I have tried some other suggestions here but it seems unless the form
> > is visible (not hidden) setting the Top and Left positions have no
> > effect and the form opens in the top left corner of the MDI Parent.
> >
> > Thanks!
> >
> >
> > rowe_newsgroups wrote:
> > > Just put the code under Sub New After the InitializeCompenent call. As
> > > for the answer to the me.hide question, you can just set me.visible =
> > > false.
> > >
> > > Thanks,
> > >
> > > Seth Rowe
> > >
> > >
> > > bwad***@gmail.com wrote:
> > > > Hi,
> > > >
> > > > Im fairly new to VB.NET and am hoping someone can help me with what is
> > > > probably a simple problem.
> > > >
> > > > I have an MDI app, when I open a child form, I want it centered to the
> > > > parent.  So I put some code in the FormLoad procedure which works out
> > > > the centre of the screen and moves the child appropraitely.
> > > >
> > > > This is pretty much the code I have:
> > > >
> > > >         MdiParent = frmMain
> > > >         Me.Top = ((frmMain.Height - Me.Height) / 2)
> > > >         Me.Left = ((frmMain.Width - Me.Width) / 2)
> > > >         Refresh_VehicleList()
> > > >
> > > > The problem is that when this window opens, you can actually see the
> > > > form move. It seems that if i remove the call to refresh_vehiclelist
> > > > that the problem isnt as bad, but is still visible. This procedure
> > > > makes SQL server calls so tends to pause briefly as it opens the
> > > > connection.  Its not a speed issue with the hardware as its a current
> > > > Core 2 Duo system.
> > > >
> > > > My question is, is there anyway to hide the form before moving it (I
> > > > tried the Hide method but it didnt move) so that the user can not see
> > > > the form moving every time they open it?
> > > >
> > > > Many thanks in advance!
> > > >
> > > > Brad.
Author
11 Oct 2006 4:22 PM
rowe_newsgroups
I still haven't found an answer for "why", but for now you should just
call me.visible = false before you set the location of the child. Also,
the form shouldn't show in the form_load event unless you explicitly
tell it to (me.show(), me.bringtofront, etc). If you're using any of
these methods before setting the location, removing them may solve the
problem.

Sorry I'm not much more help,

Seth Rowe


bwad***@gmail.com wrote:
Show quoteHide quote
> Thanks Seth for explaining that, I understand now. Shame it is still
> ignoring the properties.  Appreciate any thing you come up with.
>
> rowe_newsgroups wrote:
> > Sub New() is the construnctor for for an object - in this case the
> > form. If you type in "Sub New" and press enter the ide will change that
> > to the following:
> >
> >     Sub New()
> >
> >         ' This call is required by the Windows Form Designer.
> >         InitializeComponent()
> >
> >         ' Add any initialization after the InitializeComponent() call.
> >
> >     End Sub
> >
> > The InitializeComponent is a method that contains the code generated by
> > the designer. Any time you add a control or change it's properties it
> > is writen to this method. Generally, you want this call to occur before
> > anything else happens, that why I (and the comment line in the sub)
> > tell you to place the code after this call. Unfortunately, mdichildren
> > apperantly ignore changes to the size properties here also, so my
> > advice won't help. I'll do some research to find out why, or perhaps
> > someone else will shed some light on this.
> >
> > Thanks,
> >
> > Seth Rowe
> >
> >
> > bwad***@gmail.com wrote:
> > > Hi Seth, thanks for your help, but as i'm fairly new to vb.net, can you
> > > please explain a little further what you mean by putting the code under
> > > "Sub New"  and where the InitializeComponent call is?
> > >
> > > I have tried some other suggestions here but it seems unless the form
> > > is visible (not hidden) setting the Top and Left positions have no
> > > effect and the form opens in the top left corner of the MDI Parent.
> > >
> > > Thanks!
> > >
> > >
> > > rowe_newsgroups wrote:
> > > > Just put the code under Sub New After the InitializeCompenent call. As
> > > > for the answer to the me.hide question, you can just set me.visible =
> > > > false.
> > > >
> > > > Thanks,
> > > >
> > > > Seth Rowe
> > > >
> > > >
> > > > bwad***@gmail.com wrote:
> > > > > Hi,
> > > > >
> > > > > Im fairly new to VB.NET and am hoping someone can help me with what is
> > > > > probably a simple problem.
> > > > >
> > > > > I have an MDI app, when I open a child form, I want it centered to the
> > > > > parent.  So I put some code in the FormLoad procedure which works out
> > > > > the centre of the screen and moves the child appropraitely.
> > > > >
> > > > > This is pretty much the code I have:
> > > > >
> > > > >         MdiParent = frmMain
> > > > >         Me.Top = ((frmMain.Height - Me.Height) / 2)
> > > > >         Me.Left = ((frmMain.Width - Me.Width) / 2)
> > > > >         Refresh_VehicleList()
> > > > >
> > > > > The problem is that when this window opens, you can actually see the
> > > > > form move. It seems that if i remove the call to refresh_vehiclelist
> > > > > that the problem isnt as bad, but is still visible. This procedure
> > > > > makes SQL server calls so tends to pause briefly as it opens the
> > > > > connection.  Its not a speed issue with the hardware as its a current
> > > > > Core 2 Duo system.
> > > > >
> > > > > My question is, is there anyway to hide the form before moving it (I
> > > > > tried the Hide method but it didnt move) so that the user can not see
> > > > > the form moving every time they open it?
> > > > >
> > > > > Many thanks in advance!
> > > > >
> > > > > Brad.
Author
11 Oct 2006 4:36 PM
Steve Long
Hi Rowe,
I have run up against this before, in a non-MDI application and the only way
I could set a form's start up position to a custom location was to first set
the form's StartPosition property to manual before setting the x and y,
alternatively the location property, and then opening up the form. It works
in a MDI application as well, I just tested it.

BTW, loved your post about the Excel column hiding. It's better to teach a
man to fish and feed him for life than to give him a fish and feed him for a
day. I think you did that same type of thing with an Access question a few
days ago too. Nice.

Steve

Show quoteHide quote
"rowe_newsgroups" <rowe_em***@yahoo.com> wrote in message
news:1160583772.020097.44580@i42g2000cwa.googlegroups.com...
>I still haven't found an answer for "why", but for now you should just
> call me.visible = false before you set the location of the child. Also,
> the form shouldn't show in the form_load event unless you explicitly
> tell it to (me.show(), me.bringtofront, etc). If you're using any of
> these methods before setting the location, removing them may solve the
> problem.
>
> Sorry I'm not much more help,
>
> Seth Rowe
>
>
> bwad***@gmail.com wrote:
>> Thanks Seth for explaining that, I understand now. Shame it is still
>> ignoring the properties.  Appreciate any thing you come up with.
>>
>> rowe_newsgroups wrote:
>> > Sub New() is the construnctor for for an object - in this case the
>> > form. If you type in "Sub New" and press enter the ide will change that
>> > to the following:
>> >
>> >     Sub New()
>> >
>> >         ' This call is required by the Windows Form Designer.
>> >         InitializeComponent()
>> >
>> >         ' Add any initialization after the InitializeComponent() call.
>> >
>> >     End Sub
>> >
>> > The InitializeComponent is a method that contains the code generated by
>> > the designer. Any time you add a control or change it's properties it
>> > is writen to this method. Generally, you want this call to occur before
>> > anything else happens, that why I (and the comment line in the sub)
>> > tell you to place the code after this call. Unfortunately, mdichildren
>> > apperantly ignore changes to the size properties here also, so my
>> > advice won't help. I'll do some research to find out why, or perhaps
>> > someone else will shed some light on this.
>> >
>> > Thanks,
>> >
>> > Seth Rowe
>> >
>> >
>> > bwad***@gmail.com wrote:
>> > > Hi Seth, thanks for your help, but as i'm fairly new to vb.net, can
>> > > you
>> > > please explain a little further what you mean by putting the code
>> > > under
>> > > "Sub New"  and where the InitializeComponent call is?
>> > >
>> > > I have tried some other suggestions here but it seems unless the form
>> > > is visible (not hidden) setting the Top and Left positions have no
>> > > effect and the form opens in the top left corner of the MDI Parent.
>> > >
>> > > Thanks!
>> > >
>> > >
>> > > rowe_newsgroups wrote:
>> > > > Just put the code under Sub New After the InitializeCompenent call.
>> > > > As
>> > > > for the answer to the me.hide question, you can just set me.visible
>> > > > =
>> > > > false.
>> > > >
>> > > > Thanks,
>> > > >
>> > > > Seth Rowe
>> > > >
>> > > >
>> > > > bwad***@gmail.com wrote:
>> > > > > Hi,
>> > > > >
>> > > > > Im fairly new to VB.NET and am hoping someone can help me with
>> > > > > what is
>> > > > > probably a simple problem.
>> > > > >
>> > > > > I have an MDI app, when I open a child form, I want it centered
>> > > > > to the
>> > > > > parent.  So I put some code in the FormLoad procedure which works
>> > > > > out
>> > > > > the centre of the screen and moves the child appropraitely.
>> > > > >
>> > > > > This is pretty much the code I have:
>> > > > >
>> > > > >         MdiParent = frmMain
>> > > > >         Me.Top = ((frmMain.Height - Me.Height) / 2)
>> > > > >         Me.Left = ((frmMain.Width - Me.Width) / 2)
>> > > > >         Refresh_VehicleList()
>> > > > >
>> > > > > The problem is that when this window opens, you can actually see
>> > > > > the
>> > > > > form move. It seems that if i remove the call to
>> > > > > refresh_vehiclelist
>> > > > > that the problem isnt as bad, but is still visible. This
>> > > > > procedure
>> > > > > makes SQL server calls so tends to pause briefly as it opens the
>> > > > > connection.  Its not a speed issue with the hardware as its a
>> > > > > current
>> > > > > Core 2 Duo system.
>> > > > >
>> > > > > My question is, is there anyway to hide the form before moving it
>> > > > > (I
>> > > > > tried the Hide method but it didnt move) so that the user can not
>> > > > > see
>> > > > > the form moving every time they open it?
>> > > > >
>> > > > > Many thanks in advance!
>> > > > >
>> > > > > Brad.
>
Author
10 Oct 2006 10:54 PM
Steve Long
What about using the StartPosition property before you actually open the
form? Will that help?

Dim frm As New Form2

frm.StartPosition = FormStartPosition.CenterParent

frm.Visible = True


Steve

<bwad***@gmail.com> wrote in message
Show quoteHide quote
news:1160511409.811460.291750@c28g2000cwb.googlegroups.com...
> Hi,
>
> Im fairly new to VB.NET and am hoping someone can help me with what is
> probably a simple problem.
>
> I have an MDI app, when I open a child form, I want it centered to the
> parent.  So I put some code in the FormLoad procedure which works out
> the centre of the screen and moves the child appropraitely.
>
> This is pretty much the code I have:
>
>        MdiParent = frmMain
>        Me.Top = ((frmMain.Height - Me.Height) / 2)
>        Me.Left = ((frmMain.Width - Me.Width) / 2)
>        Refresh_VehicleList()
>
> The problem is that when this window opens, you can actually see the
> form move. It seems that if i remove the call to refresh_vehiclelist
> that the problem isnt as bad, but is still visible. This procedure
> makes SQL server calls so tends to pause briefly as it opens the
> connection.  Its not a speed issue with the hardware as its a current
> Core 2 Duo system.
>
> My question is, is there anyway to hide the form before moving it (I
> tried the Hide method but it didnt move) so that the user can not see
> the form moving every time they open it?
>
> Many thanks in advance!
>
> Brad.
>
Author
10 Oct 2006 11:17 PM
rowe_newsgroups
I believe that mdi child forms ignore the StartPosition property. Not
100% sure however.

Thanks,

Seth Rowe


Steve Long wrote:
Show quoteHide quote
> What about using the StartPosition property before you actually open the
> form? Will that help?
>
> Dim frm As New Form2
>
> frm.StartPosition = FormStartPosition.CenterParent
>
> frm.Visible = True
>
>
> Steve
>
> <bwad***@gmail.com> wrote in message
> news:1160511409.811460.291750@c28g2000cwb.googlegroups.com...
> > Hi,
> >
> > Im fairly new to VB.NET and am hoping someone can help me with what is
> > probably a simple problem.
> >
> > I have an MDI app, when I open a child form, I want it centered to the
> > parent.  So I put some code in the FormLoad procedure which works out
> > the centre of the screen and moves the child appropraitely.
> >
> > This is pretty much the code I have:
> >
> >        MdiParent = frmMain
> >        Me.Top = ((frmMain.Height - Me.Height) / 2)
> >        Me.Left = ((frmMain.Width - Me.Width) / 2)
> >        Refresh_VehicleList()
> >
> > The problem is that when this window opens, you can actually see the
> > form move. It seems that if i remove the call to refresh_vehiclelist
> > that the problem isnt as bad, but is still visible. This procedure
> > makes SQL server calls so tends to pause briefly as it opens the
> > connection.  Its not a speed issue with the hardware as its a current
> > Core 2 Duo system.
> >
> > My question is, is there anyway to hide the form before moving it (I
> > tried the Hide method but it didnt move) so that the user can not see
> > the form moving every time they open it?
> >
> > Many thanks in advance!
> >
> > Brad.
> >
Author
10 Oct 2006 10:54 PM
Steve Long
What about using the StartPosition property before you actually open the
form? Will that help?

Dim frm As New Form2

frm.StartPosition = FormStartPosition.CenterParent

frm.Visible = True


Steve

<bwad***@gmail.com> wrote in message
Show quoteHide quote
news:1160511409.811460.291750@c28g2000cwb.googlegroups.com...
> Hi,
>
> Im fairly new to VB.NET and am hoping someone can help me with what is
> probably a simple problem.
>
> I have an MDI app, when I open a child form, I want it centered to the
> parent.  So I put some code in the FormLoad procedure which works out
> the centre of the screen and moves the child appropraitely.
>
> This is pretty much the code I have:
>
>        MdiParent = frmMain
>        Me.Top = ((frmMain.Height - Me.Height) / 2)
>        Me.Left = ((frmMain.Width - Me.Width) / 2)
>        Refresh_VehicleList()
>
> The problem is that when this window opens, you can actually see the
> form move. It seems that if i remove the call to refresh_vehiclelist
> that the problem isnt as bad, but is still visible. This procedure
> makes SQL server calls so tends to pause briefly as it opens the
> connection.  Its not a speed issue with the hardware as its a current
> Core 2 Duo system.
>
> My question is, is there anyway to hide the form before moving it (I
> tried the Hide method but it didnt move) so that the user can not see
> the form moving every time they open it?
>
> Many thanks in advance!
>
> Brad.
>
Author
11 Oct 2006 3:14 PM
Steve Long
Brad, try this:
Dim frm As frmMDIChild1

Dim size As Size

size.Width = Me.Width / 2

size.Height = Me.Height / 2

frm = New frmMDIChild1

frm.MdiParent = Me        ' this is the MDI parent

frm.StartPosition = FormStartPosition.Manual

frm.Left = 20

frm.Top = 20

frm.Size = size

'frm.StartPosition = FormStartPosition.CenterParent

frm.Show()



HTH

Steve

<bwad***@gmail.com> wrote in message
Show quoteHide quote
news:1160511409.811460.291750@c28g2000cwb.googlegroups.com...
> Hi,
>
> Im fairly new to VB.NET and am hoping someone can help me with what is
> probably a simple problem.
>
> I have an MDI app, when I open a child form, I want it centered to the
> parent.  So I put some code in the FormLoad procedure which works out
> the centre of the screen and moves the child appropraitely.
>
> This is pretty much the code I have:
>
>        MdiParent = frmMain
>        Me.Top = ((frmMain.Height - Me.Height) / 2)
>        Me.Left = ((frmMain.Width - Me.Width) / 2)
>        Refresh_VehicleList()
>
> The problem is that when this window opens, you can actually see the
> form move. It seems that if i remove the call to refresh_vehiclelist
> that the problem isnt as bad, but is still visible. This procedure
> makes SQL server calls so tends to pause briefly as it opens the
> connection.  Its not a speed issue with the hardware as its a current
> Core 2 Duo system.
>
> My question is, is there anyway to hide the form before moving it (I
> tried the Hide method but it didnt move) so that the user can not see
> the form moving every time they open it?
>
> Many thanks in advance!
>
> Brad.
>
Author
11 Oct 2006 4:04 PM
bwadley
Hi Steve thanks for helping however your code simply opens up an mdi
child in the top left, even if I try and center it. I also am trying to
center a form designed in the IDE...  I don't uderstand why this is so
hard, surely what I am trying to do is not uncommon?

Thanks again for your help.


Steve Long wrote:
Show quoteHide quote
> Brad, try this:
> Dim frm As frmMDIChild1
>
> Dim size As Size
>
> size.Width = Me.Width / 2
>
> size.Height = Me.Height / 2
>
> frm = New frmMDIChild1
>
> frm.MdiParent = Me        ' this is the MDI parent
>
> frm.StartPosition = FormStartPosition.Manual
>
> frm.Left = 20
>
> frm.Top = 20
>
> frm.Size = size
>
> 'frm.StartPosition = FormStartPosition.CenterParent
>
> frm.Show()
>
>
>
> HTH
>
> Steve
>
> <bwad***@gmail.com> wrote in message
> news:1160511409.811460.291750@c28g2000cwb.googlegroups.com...
> > Hi,
> >
> > Im fairly new to VB.NET and am hoping someone can help me with what is
> > probably a simple problem.
> >
> > I have an MDI app, when I open a child form, I want it centered to the
> > parent.  So I put some code in the FormLoad procedure which works out
> > the centre of the screen and moves the child appropraitely.
> >
> > This is pretty much the code I have:
> >
> >        MdiParent = frmMain
> >        Me.Top = ((frmMain.Height - Me.Height) / 2)
> >        Me.Left = ((frmMain.Width - Me.Width) / 2)
> >        Refresh_VehicleList()
> >
> > The problem is that when this window opens, you can actually see the
> > form move. It seems that if i remove the call to refresh_vehiclelist
> > that the problem isnt as bad, but is still visible. This procedure
> > makes SQL server calls so tends to pause briefly as it opens the
> > connection.  Its not a speed issue with the hardware as its a current
> > Core 2 Duo system.
> >
> > My question is, is there anyway to hide the form before moving it (I
> > tried the Hide method but it didnt move) so that the user can not see
> > the form moving every time they open it?
> >
> > Many thanks in advance!
> >
> > Brad.
> >
Author
11 Oct 2006 4:18 PM
Steve Long
Brad,
if you set the form's StartPosition to Manual, as I have in the code below,
you can then size the form and position it prior to opening it. I tried this
in a MDI application on my own system so I know that it works. However, if
you fail to set the StartPosition to Manual, it will mearly open up a form
in the top, left position. The whole trick is setting the StartPosition to
Manual first.

Steve

<bwad***@gmail.com> wrote in message
Show quoteHide quote
news:1160582682.597826.284090@i42g2000cwa.googlegroups.com...
> Hi Steve thanks for helping however your code simply opens up an mdi
> child in the top left, even if I try and center it. I also am trying to
> center a form designed in the IDE...  I don't uderstand why this is so
> hard, surely what I am trying to do is not uncommon?
>
> Thanks again for your help.
>
>
> Steve Long wrote:
>> Brad, try this:
>> Dim frm As frmMDIChild1
>>
>> Dim size As Size
>>
>> size.Width = Me.Width / 2
>>
>> size.Height = Me.Height / 2
>>
>> frm = New frmMDIChild1
>>
>> frm.MdiParent = Me        ' this is the MDI parent
>>
>> frm.StartPosition = FormStartPosition.Manual
>>
>> frm.Left = 20
>>
>> frm.Top = 20
>>
>> frm.Size = size
>>
>> 'frm.StartPosition = FormStartPosition.CenterParent
>>
>> frm.Show()
>>
>>
>>
>> HTH
>>
>> Steve
>>
>> <bwad***@gmail.com> wrote in message
>> news:1160511409.811460.291750@c28g2000cwb.googlegroups.com...
>> > Hi,
>> >
>> > Im fairly new to VB.NET and am hoping someone can help me with what is
>> > probably a simple problem.
>> >
>> > I have an MDI app, when I open a child form, I want it centered to the
>> > parent.  So I put some code in the FormLoad procedure which works out
>> > the centre of the screen and moves the child appropraitely.
>> >
>> > This is pretty much the code I have:
>> >
>> >        MdiParent = frmMain
>> >        Me.Top = ((frmMain.Height - Me.Height) / 2)
>> >        Me.Left = ((frmMain.Width - Me.Width) / 2)
>> >        Refresh_VehicleList()
>> >
>> > The problem is that when this window opens, you can actually see the
>> > form move. It seems that if i remove the call to refresh_vehiclelist
>> > that the problem isnt as bad, but is still visible. This procedure
>> > makes SQL server calls so tends to pause briefly as it opens the
>> > connection.  Its not a speed issue with the hardware as its a current
>> > Core 2 Duo system.
>> >
>> > My question is, is there anyway to hide the form before moving it (I
>> > tried the Hide method but it didnt move) so that the user can not see
>> > the form moving every time they open it?
>> >
>> > Many thanks in advance!
>> >
>> > Brad.
>> >
>
Author
11 Oct 2006 5:38 PM
teslar91
Steve Long wrote:
> Brad,
> if you set the form's StartPosition to Manual, as I have in the code below,
> you can then size the form and position it prior to opening it. I tried this
> in a MDI application on my own system so I know that it works. However, if
> you fail to set the StartPosition to Manual, it will mearly open up a form
> in the top, left position. The whole trick is setting the StartPosition to
> Manual first.

I didn't know about that trick, I'll have to try that. :)

I've been dealing with this a different way.  Following is a copy of my
response to another current thread.  If nothing else, notice that I
take into account the possibility that the Child is wider/taller than
the Parent's client area, and never set the Top/Left less than zero;
which would hide part or all of the title bar:

-----

MDI children ignore the StartPosition property, as well as any other
attempt to set their position prior to .Show.

Put this in the Load event of every MDI child form you want centered:

  CenterInParent(Me)

And this in a module:

  Sub CenterInParent(ByRef frm As Object)
    frm.Left = Higher((frm.Parent.ClientSize.Width - frm.Width) / 2, 0)

    frm.Top = Higher((frm.Parent.ClientSize.Height - frm.Height) / 2,
0)
  End Sub

  Function Higher(ByRef x, ByRef y)
    Higher = IIf(x > y, x, y)
  End Function
Author
11 Oct 2006 4:19 PM
Steve Long
Opps, I forgot to take out the line:
'frm.StartPosition = FormStartPosition.CenterParent
which was commented out anyway. Make sure you take that line out.

Steve

<bwad***@gmail.com> wrote in message
Show quoteHide quote
news:1160582682.597826.284090@i42g2000cwa.googlegroups.com...
> Hi Steve thanks for helping however your code simply opens up an mdi
> child in the top left, even if I try and center it. I also am trying to
> center a form designed in the IDE...  I don't uderstand why this is so
> hard, surely what I am trying to do is not uncommon?
>
> Thanks again for your help.
>
>
> Steve Long wrote:
>> Brad, try this:
>> Dim frm As frmMDIChild1
>>
>> Dim size As Size
>>
>> size.Width = Me.Width / 2
>>
>> size.Height = Me.Height / 2
>>
>> frm = New frmMDIChild1
>>
>> frm.MdiParent = Me        ' this is the MDI parent
>>
>> frm.StartPosition = FormStartPosition.Manual
>>
>> frm.Left = 20
>>
>> frm.Top = 20
>>
>> frm.Size = size
>>
>> 'frm.StartPosition = FormStartPosition.CenterParent
>>
>> frm.Show()
>>
>>
>>
>> HTH
>>
>> Steve
>>
>> <bwad***@gmail.com> wrote in message
>> news:1160511409.811460.291750@c28g2000cwb.googlegroups.com...
>> > Hi,
>> >
>> > Im fairly new to VB.NET and am hoping someone can help me with what is
>> > probably a simple problem.
>> >
>> > I have an MDI app, when I open a child form, I want it centered to the
>> > parent.  So I put some code in the FormLoad procedure which works out
>> > the centre of the screen and moves the child appropraitely.
>> >
>> > This is pretty much the code I have:
>> >
>> >        MdiParent = frmMain
>> >        Me.Top = ((frmMain.Height - Me.Height) / 2)
>> >        Me.Left = ((frmMain.Width - Me.Width) / 2)
>> >        Refresh_VehicleList()
>> >
>> > The problem is that when this window opens, you can actually see the
>> > form move. It seems that if i remove the call to refresh_vehiclelist
>> > that the problem isnt as bad, but is still visible. This procedure
>> > makes SQL server calls so tends to pause briefly as it opens the
>> > connection.  Its not a speed issue with the hardware as its a current
>> > Core 2 Duo system.
>> >
>> > My question is, is there anyway to hide the form before moving it (I
>> > tried the Hide method but it didnt move) so that the user can not see
>> > the form moving every time they open it?
>> >
>> > Many thanks in advance!
>> >
>> > Brad.
>> >
>