473,404 Members | 2,187 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,404 software developers and data experts.

Q: Parent of a form

Hi

Suppose I have two forms: Form1 and Form2. I create and show an instance of
Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at
either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Can anybody help???

Thanks in advance

Geoff
Nov 21 '05 #1
37 2051
"Geoff Jones" <ge***@NODAMNSPAM.com> schrieb:
Suppose I have two forms: Form1 and Form2. I create and show an instance
of
Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at
either "Parent" or "ParentForm" in Form2, they both show "Nothing".


Do you want to show your form modally?

\\\
Dim MyForm2 As New Form2()
MyForm2.ShowDialog()
///

--
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
try using .showdialog to set the parent

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi

Suppose I have two forms: Form1 and Form2. I create and show an instance of Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at
either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Can anybody help???

Thanks in advance

Geoff

Nov 21 '05 #3
Hi

Thanks for your advice; although I don't think what you are suggesting is
exactly what I require.

In Form2, I have a progress control, which I am using to display the
progress of calculations in Form1. If I understand ShowDialog correctly,
using this, the program will stop within Form1. I suppose I could use
Threads, as others in the newsgroup have kindly suggested, however, I still
think there must be a way to do it using the technique I have described i.e.
show the form with the progress control in the first form, and increment the
control from within Form1 e.g.

theProgressControl.Increment(1) ' This is called within Form1

This does indeed work. However, I want the second form i.e. the one with the
progress control, to be centered in the first form. I've tried using:

myForm2.StartPosition = FormStartPosition.CenterParent

but this does not do what I expect i.e. it isn't centered on the first form.

Can anybody help?

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
"Geoff Jones" <ge***@NODAMNSPAM.com> schrieb:
Suppose I have two forms: Form1 and Form2. I create and show an instance
of
Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at
either "Parent" or "ParentForm" in Form2, they both show "Nothing".


Do you want to show your form modally?

\\\
Dim MyForm2 As New Form2()
MyForm2.ShowDialog()
///

--
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 #4
Geoff,

I find this question (I have seen it more) forever weird, therefore I am
curious for the reason you do it this way and not just use an almost
foerever hidded panel that you hide and make visible.

The only thing you have to think than about is that you set the Zorder of
the panel right.

However maybe you have a special reason for the form and I am curious for
that. Will you tell why?

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
Hi

Suppose I have two forms: Form1 and Form2. I create and show an instance
of
Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at
either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Can anybody help???

Thanks in advance

Geoff

Nov 21 '05 #5
myForm2.StartPosition = FormStartPosition.CenterParent

works for me
maybe try to do it manually

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi

Thanks for your advice; although I don't think what you are suggesting is
exactly what I require.

In Form2, I have a progress control, which I am using to display the
progress of calculations in Form1. If I understand ShowDialog correctly,
using this, the program will stop within Form1. I suppose I could use
Threads, as others in the newsgroup have kindly suggested, however, I still think there must be a way to do it using the technique I have described i.e. show the form with the progress control in the first form, and increment the control from within Form1 e.g.

theProgressControl.Increment(1) ' This is called within Form1

This does indeed work. However, I want the second form i.e. the one with the progress control, to be centered in the first form. I've tried using:

myForm2.StartPosition = FormStartPosition.CenterParent

but this does not do what I expect i.e. it isn't centered on the first form.
Can anybody help?

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
"Geoff Jones" <ge***@NODAMNSPAM.com> schrieb:
Suppose I have two forms: Form1 and Form2. I create and show an instance of
Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at either "Parent" or "ParentForm" in Form2, they both show "Nothing".


Do you want to show your form modally?

\\\
Dim MyForm2 As New Form2()
MyForm2.ShowDialog()
///

--
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 #6
Hi David

In which member do you write this line of code? Maybe I'm putting it in the
wrong place?

Geoff

"David Gacek" <so*****@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP09.phx.gbl...
myForm2.StartPosition = FormStartPosition.CenterParent

works for me
maybe try to do it manually

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi

Thanks for your advice; although I don't think what you are suggesting is
exactly what I require.

In Form2, I have a progress control, which I am using to display the
progress of calculations in Form1. If I understand ShowDialog correctly,
using this, the program will stop within Form1. I suppose I could use
Threads, as others in the newsgroup have kindly suggested, however, I

still
think there must be a way to do it using the technique I have described

i.e.
show the form with the progress control in the first form, and increment

the
control from within Form1 e.g.

theProgressControl.Increment(1) ' This is called within Form1

This does indeed work. However, I want the second form i.e. the one with

the
progress control, to be centered in the first form. I've tried using:

myForm2.StartPosition = FormStartPosition.CenterParent

but this does not do what I expect i.e. it isn't centered on the first

form.

Can anybody help?

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
"Geoff Jones" <ge***@NODAMNSPAM.com> schrieb:
> Suppose I have two forms: Form1 and Form2. I create and show an

instance > of
> Form2 in the code of Form1 e.g.
>
> Dim myForm2 = New Form2
> myForm2.Show()
>
> How do I tell myForm2 that Form1 is its parent? That is, when I look at > either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Do you want to show your form modally?

\\\
Dim MyForm2 As New Form2()
MyForm2.ShowDialog()
///

--
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 #7
Hi Cor

You're idea of using an forever hidden panel is interesting. I may give it a
go.

However, I am still puzzled why my code is not working. Being from a C++
background, I'm trying to understand VB.net and I can't understand why
CenterParent does not work. This, as with most things, has made me ask some
other questions as you have seen. For example, how do I tell Form2 that
Form1 is the calling routine i.e. it is the parent. I would have thought it
would have implicitly passed a pointer to Form2 to say that Form1 was the
parent. If it doesn't, how do I pass a pointer to Form2 to tell it that Form
1 is a pointer i.e. in C++ I would have passed a "this" pointer explicitly.

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e4*************@TK2MSFTNGP12.phx.gbl...
Geoff,

I find this question (I have seen it more) forever weird, therefore I am
curious for the reason you do it this way and not just use an almost
foerever hidded panel that you hide and make visible.

The only thing you have to think than about is that you set the Zorder of
the panel right.

However maybe you have a special reason for the form and I am curious for
that. Will you tell why?

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
Hi

Suppose I have two forms: Form1 and Form2. I create and show an instance
of
Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at
either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Can anybody help???

Thanks in advance

Geoff


Nov 21 '05 #8
Hi

I'm putting the line:

Me.StartPosition = FormStartPosition.CenterScreen

in Form1_Load to see if I can center Form1 as an experiment. It does not
work! So I must be placing it in the wrong place.

Can anybody enlighten me?

Geoff

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi David

In which member do you write this line of code? Maybe I'm putting it in the wrong place?

Geoff

"David Gacek" <so*****@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP09.phx.gbl...
myForm2.StartPosition = FormStartPosition.CenterParent

works for me
maybe try to do it manually

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi

Thanks for your advice; although I don't think what you are suggesting is exactly what I require.

In Form2, I have a progress control, which I am using to display the
progress of calculations in Form1. If I understand ShowDialog correctly, using this, the program will stop within Form1. I suppose I could use
Threads, as others in the newsgroup have kindly suggested, however, I

still
think there must be a way to do it using the technique I have described
i.e.
show the form with the progress control in the first form, and
increment the
control from within Form1 e.g.

theProgressControl.Increment(1) ' This is called within Form1

This does indeed work. However, I want the second form i.e. the one
with the
progress control, to be centered in the first form. I've tried using:

myForm2.StartPosition = FormStartPosition.CenterParent

but this does not do what I expect i.e. it isn't centered on the first

form.

Can anybody help?

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> "Geoff Jones" <ge***@NODAMNSPAM.com> schrieb:
> > Suppose I have two forms: Form1 and Form2. I create and show an

instance
> > of
> > Form2 in the code of Form1 e.g.
> >
> > Dim myForm2 = New Form2
> > myForm2.Show()
> >
> > How do I tell myForm2 that Form1 is its parent? That is, when I
look at
> > either "Parent" or "ParentForm" in Form2, they both show

"Nothing". >
> Do you want to show your form modally?
>
> \\\
> Dim MyForm2 As New Form2()
> MyForm2.ShowDialog()
> ///
>
> --
> 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 #9
I've just tried something else. If I write:

Me.WindowState = FormWindowState.Maximised

in Form1_Load, it does indeed maximise the window

BUT!!!!!

If I write

Me.StartPosition = FormStartPosition.CenterScreen

it doesn't work! i.e. the form is displayed not in the center!!!!

Is this a bug or am I going mad???????? LOL

Geoff

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi David

In which member do you write this line of code? Maybe I'm putting it in the wrong place?

Geoff

"David Gacek" <so*****@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP09.phx.gbl...
myForm2.StartPosition = FormStartPosition.CenterParent

works for me
maybe try to do it manually

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi

Thanks for your advice; although I don't think what you are suggesting is exactly what I require.

In Form2, I have a progress control, which I am using to display the
progress of calculations in Form1. If I understand ShowDialog correctly, using this, the program will stop within Form1. I suppose I could use
Threads, as others in the newsgroup have kindly suggested, however, I

still
think there must be a way to do it using the technique I have described
i.e.
show the form with the progress control in the first form, and
increment the
control from within Form1 e.g.

theProgressControl.Increment(1) ' This is called within Form1

This does indeed work. However, I want the second form i.e. the one
with the
progress control, to be centered in the first form. I've tried using:

myForm2.StartPosition = FormStartPosition.CenterParent

but this does not do what I expect i.e. it isn't centered on the first

form.

Can anybody help?

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> "Geoff Jones" <ge***@NODAMNSPAM.com> schrieb:
> > Suppose I have two forms: Form1 and Form2. I create and show an

instance
> > of
> > Form2 in the code of Form1 e.g.
> >
> > Dim myForm2 = New Form2
> > myForm2.Show()
> >
> > How do I tell myForm2 that Form1 is its parent? That is, when I
look at
> > either "Parent" or "ParentForm" in Form2, they both show

"Nothing". >
> Do you want to show your form modally?
>
> \\\
> Dim MyForm2 As New Form2()
> MyForm2.ShowDialog()
> ///
>
> --
> 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 #10
Hi David

Just to make it clear, I am doing all this manually i.e. I'm not setting the
Form location in the properties window of the IDE.

Geoff

"David Gacek" <so*****@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP09.phx.gbl...
myForm2.StartPosition = FormStartPosition.CenterParent

works for me
maybe try to do it manually

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi

Thanks for your advice; although I don't think what you are suggesting is
exactly what I require.

In Form2, I have a progress control, which I am using to display the
progress of calculations in Form1. If I understand ShowDialog correctly,
using this, the program will stop within Form1. I suppose I could use
Threads, as others in the newsgroup have kindly suggested, however, I

still
think there must be a way to do it using the technique I have described

i.e.
show the form with the progress control in the first form, and increment

the
control from within Form1 e.g.

theProgressControl.Increment(1) ' This is called within Form1

This does indeed work. However, I want the second form i.e. the one with

the
progress control, to be centered in the first form. I've tried using:

myForm2.StartPosition = FormStartPosition.CenterParent

but this does not do what I expect i.e. it isn't centered on the first

form.

Can anybody help?

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
"Geoff Jones" <ge***@NODAMNSPAM.com> schrieb:
> Suppose I have two forms: Form1 and Form2. I create and show an

instance > of
> Form2 in the code of Form1 e.g.
>
> Dim myForm2 = New Form2
> myForm2.Show()
>
> How do I tell myForm2 that Form1 is its parent? That is, when I look at > either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Do you want to show your form modally?

\\\
Dim MyForm2 As New Form2()
MyForm2.ShowDialog()
///

--
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 #11
Hi

I'm putting the line:

Me.StartPosition = FormStartPosition.CenterScreen

in Form1_Load to see if I can center Form1 as an experiment. It does not
work! So I must be placing it in the wrong place.

Can anybody enlighten me?

Geoff

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi David

In which member do you write this line of code? Maybe I'm putting it in the wrong place?

Geoff

"David Gacek" <so*****@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP09.phx.gbl...
myForm2.StartPosition = FormStartPosition.CenterParent

works for me
maybe try to do it manually

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi

Thanks for your advice; although I don't think what you are suggesting is exactly what I require.

In Form2, I have a progress control, which I am using to display the
progress of calculations in Form1. If I understand ShowDialog correctly, using this, the program will stop within Form1. I suppose I could use
Threads, as others in the newsgroup have kindly suggested, however, I

still
think there must be a way to do it using the technique I have described
i.e.
show the form with the progress control in the first form, and
increment the
control from within Form1 e.g.

theProgressControl.Increment(1) ' This is called within Form1

This does indeed work. However, I want the second form i.e. the one
with the
progress control, to be centered in the first form. I've tried using:

myForm2.StartPosition = FormStartPosition.CenterParent

but this does not do what I expect i.e. it isn't centered on the first

form.

Can anybody help?

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> "Geoff Jones" <ge***@NODAMNSPAM.com> schrieb:
> > Suppose I have two forms: Form1 and Form2. I create and show an

instance
> > of
> > Form2 in the code of Form1 e.g.
> >
> > Dim myForm2 = New Form2
> > myForm2.Show()
> >
> > How do I tell myForm2 that Form1 is its parent? That is, when I
look at
> > either "Parent" or "ParentForm" in Form2, they both show

"Nothing". >
> Do you want to show your form modally?
>
> \\\
> Dim MyForm2 As New Form2()
> MyForm2.ShowDialog()
> ///
>
> --
> 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 #12
I've just tried something else. If I write:

Me.WindowState = FormWindowState.Maximised

in Form1_Load, it does indeed maximise the window

BUT!!!!!

If I write

Me.StartPosition = FormStartPosition.CenterScreen

it doesn't work! i.e. the form is displayed not in the center!!!!

Is this a bug or am I going mad???????? LOL

Geoff

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi David

In which member do you write this line of code? Maybe I'm putting it in the wrong place?

Geoff

"David Gacek" <so*****@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP09.phx.gbl...
myForm2.StartPosition = FormStartPosition.CenterParent

works for me
maybe try to do it manually

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi

Thanks for your advice; although I don't think what you are suggesting is exactly what I require.

In Form2, I have a progress control, which I am using to display the
progress of calculations in Form1. If I understand ShowDialog correctly, using this, the program will stop within Form1. I suppose I could use
Threads, as others in the newsgroup have kindly suggested, however, I

still
think there must be a way to do it using the technique I have described
i.e.
show the form with the progress control in the first form, and
increment the
control from within Form1 e.g.

theProgressControl.Increment(1) ' This is called within Form1

This does indeed work. However, I want the second form i.e. the one
with the
progress control, to be centered in the first form. I've tried using:

myForm2.StartPosition = FormStartPosition.CenterParent

but this does not do what I expect i.e. it isn't centered on the first

form.

Can anybody help?

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> "Geoff Jones" <ge***@NODAMNSPAM.com> schrieb:
> > Suppose I have two forms: Form1 and Form2. I create and show an

instance
> > of
> > Form2 in the code of Form1 e.g.
> >
> > Dim myForm2 = New Form2
> > myForm2.Show()
> >
> > How do I tell myForm2 that Form1 is its parent? That is, when I
look at
> > either "Parent" or "ParentForm" in Form2, they both show

"Nothing". >
> Do you want to show your form modally?
>
> \\\
> Dim MyForm2 As New Form2()
> MyForm2.ShowDialog()
> ///
>
> --
> 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 #13
Hi David

Just to make it clear, I am doing all this manually i.e. I'm not setting the
Form location in the properties window of the IDE.

Geoff

"David Gacek" <so*****@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP09.phx.gbl...
myForm2.StartPosition = FormStartPosition.CenterParent

works for me
maybe try to do it manually

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hi

Thanks for your advice; although I don't think what you are suggesting is
exactly what I require.

In Form2, I have a progress control, which I am using to display the
progress of calculations in Form1. If I understand ShowDialog correctly,
using this, the program will stop within Form1. I suppose I could use
Threads, as others in the newsgroup have kindly suggested, however, I

still
think there must be a way to do it using the technique I have described

i.e.
show the form with the progress control in the first form, and increment

the
control from within Form1 e.g.

theProgressControl.Increment(1) ' This is called within Form1

This does indeed work. However, I want the second form i.e. the one with

the
progress control, to be centered in the first form. I've tried using:

myForm2.StartPosition = FormStartPosition.CenterParent

but this does not do what I expect i.e. it isn't centered on the first

form.

Can anybody help?

Geoff

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
"Geoff Jones" <ge***@NODAMNSPAM.com> schrieb:
> Suppose I have two forms: Form1 and Form2. I create and show an

instance > of
> Form2 in the code of Form1 e.g.
>
> Dim myForm2 = New Form2
> myForm2.Show()
>
> How do I tell myForm2 that Form1 is its parent? That is, when I look at > either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Do you want to show your form modally?

\\\
Dim MyForm2 As New Form2()
MyForm2.ShowDialog()
///

--
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 #14

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote
Is this a bug or am I going mad???????? LOL


There is always the concern that you do things in their proper order.

You have to have gas in the tank before turning the ignition key will
work to start the car, right?

It may be, the StartPosition property has already been used to position
the form, before you get to the Form_Load event. No matter what you
set it to in Form_Load, it won't effect the form's position because that
property may have already been used to position the form.

Try adding it to the form's New sub (In the Designer generated section)
or setting it via the IDE....

<g>
LFS


Nov 21 '05 #15

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote
Is this a bug or am I going mad???????? LOL


There is always the concern that you do things in their proper order.

You have to have gas in the tank before turning the ignition key will
work to start the car, right?

It may be, the StartPosition property has already been used to position
the form, before you get to the Form_Load event. No matter what you
set it to in Form_Load, it won't effect the form's position because that
property may have already been used to position the form.

Try adding it to the form's New sub (In the Designer generated section)
or setting it via the IDE....

<g>
LFS


Nov 21 '05 #16
Hi Larry

I did a text search for StartPosition and it only occurs if I've specified
"CenterScreen" in the properties window i.e. if WindowsDefaultLocation is
selected by default then StartPosition does not appear in the code. So, as
you say, if I select CenterParent in the properties window, the startup form
is displayed in the center of the screen. If I do it manually in the code,
when the properties window shows WindowsDefaultLocation, and no StartPostion
(apart from the one I've added) is in the "Windows Forms Designer Generated
Code", then it doesn't work.

I'm going to list the steps that I've done again to see if I've done
something very silly (which is incredibly likely!!!):

(1) Start a new Windows Application
(2) In the Form1_Load member write:

Me.StartPosition = FormStartPosition.CenterScreen

(3) Run the application.

My understanding is that this should center the form in the screen. It
doesn't! However, if you set the FormStartPosition in the properties window
to CenterScreen, it does work!!!

Can anybody explain????

Geoff

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote
Is this a bug or am I going mad???????? LOL


There is always the concern that you do things in their proper order.

You have to have gas in the tank before turning the ignition key will
work to start the car, right?

It may be, the StartPosition property has already been used to position
the form, before you get to the Form_Load event. No matter what you
set it to in Form_Load, it won't effect the form's position because that
property may have already been used to position the form.

Try adding it to the form's New sub (In the Designer generated section)
or setting it via the IDE....

<g>
LFS

Nov 21 '05 #17
Oh dear.

Much head scratching later; it seems that some bright spark (who's since
left) thought it'd be fun to delete some rows from the dataset at runtime.
Without documenting this behaviour.

Quite how that got past our entire department pointing at it and going
"eh?", I'm not sure.

Anyway, this is now resolved for me :)
"Geoff Jones" wrote:
Hi

Suppose I have two forms: Form1 and Form2. I create and show an instance of
Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at
either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Can anybody help???

Thanks in advance

Geoff

Nov 21 '05 #18
Hi Larry

I did a text search for StartPosition and it only occurs if I've specified
"CenterScreen" in the properties window i.e. if WindowsDefaultLocation is
selected by default then StartPosition does not appear in the code. So, as
you say, if I select CenterParent in the properties window, the startup form
is displayed in the center of the screen. If I do it manually in the code,
when the properties window shows WindowsDefaultLocation, and no StartPostion
(apart from the one I've added) is in the "Windows Forms Designer Generated
Code", then it doesn't work.

I'm going to list the steps that I've done again to see if I've done
something very silly (which is incredibly likely!!!):

(1) Start a new Windows Application
(2) In the Form1_Load member write:

Me.StartPosition = FormStartPosition.CenterScreen

(3) Run the application.

My understanding is that this should center the form in the screen. It
doesn't! However, if you set the FormStartPosition in the properties window
to CenterScreen, it does work!!!

Can anybody explain????

Geoff

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote
Is this a bug or am I going mad???????? LOL


There is always the concern that you do things in their proper order.

You have to have gas in the tank before turning the ignition key will
work to start the car, right?

It may be, the StartPosition property has already been used to position
the form, before you get to the Form_Load event. No matter what you
set it to in Form_Load, it won't effect the form's position because that
property may have already been used to position the form.

Try adding it to the form's New sub (In the Designer generated section)
or setting it via the IDE....

<g>
LFS

Nov 21 '05 #19

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote
I'm going to list the steps that I've done again to see if I've done
something very silly (which is incredibly likely!!!):

(1) Start a new Windows Application
(2) In the Form1_Load member write:

Me.StartPosition = FormStartPosition.CenterScreen

(3) Run the application.

My understanding is that this should center the form in the screen. It
doesn't!


Did you miss this:
It may be, the StartPosition property has already been used to position
the form, before you get to the Form_Load event.
I then said:
Try adding it to the form's New sub


So, open up the designer generated section (at the top of the code) and
make it look like this:

Public Sub New()
MyBase.New()

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

'Add any initialization after the InitializeComponent() call
Me.StartPosition = FormStartPosition.CenterScreen
End Sub
LFS
Nov 21 '05 #20
Oh dear.

Much head scratching later; it seems that some bright spark (who's since
left) thought it'd be fun to delete some rows from the dataset at runtime.
Without documenting this behaviour.

Quite how that got past our entire department pointing at it and going
"eh?", I'm not sure.

Anyway, this is now resolved for me :)
"Geoff Jones" wrote:
Hi

Suppose I have two forms: Form1 and Form2. I create and show an instance of
Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at
either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Can anybody help???

Thanks in advance

Geoff

Nov 21 '05 #21
Geoff,

Is it not that your idea of a parent is not what a parent is.
http://msdn.microsoft.com/library/de...arenttopic.asp

When you want to center it to the screen, than it is in my opinion
calculating the point to screen from what you call your parent form and set
that in your child form.

When you want to set a reference do it in the same way as you said you do it
in C++ only here it is named. Me.

\\\
Private Sub Button1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim frm As New Form2
frm.Text = "geoff"
frm.Height = Me.Height - 100
frm.Width = Me.Width - 100
Me.Location = New Drawing.Point _
(Me.Location.X + 50, Me.Location.Y + 50)
frm.parentform = Me 'the C this pointer and created as property on
Form2
' with this a reference is created to the mainform on the subform
frm.Show()
End Sub.
///
In my idea do you focus to much on the existing parent property, while it is
in my idea possible as well on the "child", just referencing the "me" from
the by you created"parentform" on your child form.

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
Hi Cor

You're idea of using an forever hidden panel is interesting. I may give it
a
go.

However, I am still puzzled why my code is not working. Being from a C++
background, I'm trying to understand VB.net and I can't understand why
CenterParent does not work. This, as with most things, has made me ask
some
other questions as you have seen. For example, how do I tell Form2 that
Form1 is the calling routine i.e. it is the parent. I would have thought
it
would have implicitly passed a pointer to Form2 to say that Form1 was the
parent. If it doesn't, how do I pass a pointer to Form2 to tell it that
Form
1 is a pointer i.e. in C++ I would have passed a "this" pointer
explicitly.

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e4*************@TK2MSFTNGP12.phx.gbl...
Geoff,

I find this question (I have seen it more) forever weird, therefore I am
curious for the reason you do it this way and not just use an almost
foerever hidded panel that you hide and make visible.

The only thing you have to think than about is that you set the Zorder of
the panel right.

However maybe you have a special reason for the form and I am curious for
that. Will you tell why?

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
> Hi
>
> Suppose I have two forms: Form1 and Form2. I create and show an
> instance
> of
> Form2 in the code of Form1 e.g.
>
> Dim myForm2 = New Form2
> myForm2.Show()
>
> How do I tell myForm2 that Form1 is its parent? That is, when I look at
> either "Parent" or "ParentForm" in Form2, they both show "Nothing".
>
> Can anybody help???
>
> Thanks in advance
>
> Geoff
>
>



Nov 21 '05 #22

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote
I'm going to list the steps that I've done again to see if I've done
something very silly (which is incredibly likely!!!):

(1) Start a new Windows Application
(2) In the Form1_Load member write:

Me.StartPosition = FormStartPosition.CenterScreen

(3) Run the application.

My understanding is that this should center the form in the screen. It
doesn't!


Did you miss this:
It may be, the StartPosition property has already been used to position
the form, before you get to the Form_Load event.
I then said:
Try adding it to the form's New sub


So, open up the designer generated section (at the top of the code) and
make it look like this:

Public Sub New()
MyBase.New()

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

'Add any initialization after the InitializeComponent() call
Me.StartPosition = FormStartPosition.CenterScreen
End Sub
LFS
Nov 21 '05 #23
Geoff,

Is it not that your idea of a parent is not what a parent is.
http://msdn.microsoft.com/library/de...arenttopic.asp

When you want to center it to the screen, than it is in my opinion
calculating the point to screen from what you call your parent form and set
that in your child form.

When you want to set a reference do it in the same way as you said you do it
in C++ only here it is named. Me.

\\\
Private Sub Button1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim frm As New Form2
frm.Text = "geoff"
frm.Height = Me.Height - 100
frm.Width = Me.Width - 100
Me.Location = New Drawing.Point _
(Me.Location.X + 50, Me.Location.Y + 50)
frm.parentform = Me 'the C this pointer and created as property on
Form2
' with this a reference is created to the mainform on the subform
frm.Show()
End Sub.
///
In my idea do you focus to much on the existing parent property, while it is
in my idea possible as well on the "child", just referencing the "me" from
the by you created"parentform" on your child form.

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
Hi Cor

You're idea of using an forever hidden panel is interesting. I may give it
a
go.

However, I am still puzzled why my code is not working. Being from a C++
background, I'm trying to understand VB.net and I can't understand why
CenterParent does not work. This, as with most things, has made me ask
some
other questions as you have seen. For example, how do I tell Form2 that
Form1 is the calling routine i.e. it is the parent. I would have thought
it
would have implicitly passed a pointer to Form2 to say that Form1 was the
parent. If it doesn't, how do I pass a pointer to Form2 to tell it that
Form
1 is a pointer i.e. in C++ I would have passed a "this" pointer
explicitly.

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e4*************@TK2MSFTNGP12.phx.gbl...
Geoff,

I find this question (I have seen it more) forever weird, therefore I am
curious for the reason you do it this way and not just use an almost
foerever hidded panel that you hide and make visible.

The only thing you have to think than about is that you set the Zorder of
the panel right.

However maybe you have a special reason for the form and I am curious for
that. Will you tell why?

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
> Hi
>
> Suppose I have two forms: Form1 and Form2. I create and show an
> instance
> of
> Form2 in the code of Form1 e.g.
>
> Dim myForm2 = New Form2
> myForm2.Show()
>
> How do I tell myForm2 that Form1 is its parent? That is, when I look at
> either "Parent" or "ParentForm" in Form2, they both show "Nothing".
>
> Can anybody help???
>
> Thanks in advance
>
> Geoff
>
>



Nov 21 '05 #24
Rowland,

I am glad this helps, however that could not be the error when you did all
those test on the point I asked you. Directly after the setting to of the
datasource.

And please add this message to the original thread, I saw it because I was
busy with a answer for Geof.

Cor

"Rowland Shaw" <sp********@anotherpointless.org>
Oh dear.

Much head scratching later; it seems that some bright spark (who's since
left) thought it'd be fun to delete some rows from the dataset at runtime.
Without documenting this behaviour.

Quite how that got past our entire department pointing at it and going
"eh?", I'm not sure.

Anyway, this is now resolved for me :)
"Geoff Jones" wrote:
Hi

Suppose I have two forms: Form1 and Form2. I create and show an instance
of
Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at
either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Can anybody help???

Thanks in advance

Geoff

Nov 21 '05 #25
Rowland,

I am glad this helps, however that could not be the error when you did all
those test on the point I asked you. Directly after the setting to of the
datasource.

And please add this message to the original thread, I saw it because I was
busy with a answer for Geof.

Cor

"Rowland Shaw" <sp********@anotherpointless.org>
Oh dear.

Much head scratching later; it seems that some bright spark (who's since
left) thought it'd be fun to delete some rows from the dataset at runtime.
Without documenting this behaviour.

Quite how that got past our entire department pointing at it and going
"eh?", I'm not sure.

Anyway, this is now resolved for me :)
"Geoff Jones" wrote:
Hi

Suppose I have two forms: Form1 and Form2. I create and show an instance
of
Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at
either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Can anybody help???

Thanks in advance

Geoff

Nov 21 '05 #26
Hi Larry,

Ah, ha!!! Yes, that worked. This seems to make sense now but I'm surprised
that the documentation and various searches on this topic have not
highlighted that you have to add the code here for it to work. All the
examples I have seen just say use: StartPosition and CenterScreen.

Now, as usual, I'm awkward and going to ask a follow up question:

How do I make a form which is created in the first form, open up so that it
is centered on the first form? Okay, I know I could probably do the same
thing i.e. center it on the screen, but what if the first form is not
centered on the screen? I've tried setting the properties value of the
second form to:

FormStartPosition to CenterParent

but it doesn't work.

Any ideas?

Geoff

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:uX**************@tk2msftngp13.phx.gbl...

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote
I'm going to list the steps that I've done again to see if I've done
something very silly (which is incredibly likely!!!):

(1) Start a new Windows Application
(2) In the Form1_Load member write:

Me.StartPosition = FormStartPosition.CenterScreen

(3) Run the application.

My understanding is that this should center the form in the screen. It
doesn't!


Did you miss this:
It may be, the StartPosition property has already been used to position the form, before you get to the Form_Load event.
I then said:
Try adding it to the form's New sub


So, open up the designer generated section (at the top of the code) and
make it look like this:

Public Sub New()
MyBase.New()

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

'Add any initialization after the InitializeComponent() call
Me.StartPosition = FormStartPosition.CenterScreen
End Sub
LFS

Nov 21 '05 #27
Hi Larry,

Ah, ha!!! Yes, that worked. This seems to make sense now but I'm surprised
that the documentation and various searches on this topic have not
highlighted that you have to add the code here for it to work. All the
examples I have seen just say use: StartPosition and CenterScreen.

Now, as usual, I'm awkward and going to ask a follow up question:

How do I make a form which is created in the first form, open up so that it
is centered on the first form? Okay, I know I could probably do the same
thing i.e. center it on the screen, but what if the first form is not
centered on the screen? I've tried setting the properties value of the
second form to:

FormStartPosition to CenterParent

but it doesn't work.

Any ideas?

Geoff

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:uX**************@tk2msftngp13.phx.gbl...

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote
I'm going to list the steps that I've done again to see if I've done
something very silly (which is incredibly likely!!!):

(1) Start a new Windows Application
(2) In the Form1_Load member write:

Me.StartPosition = FormStartPosition.CenterScreen

(3) Run the application.

My understanding is that this should center the form in the screen. It
doesn't!


Did you miss this:
It may be, the StartPosition property has already been used to position the form, before you get to the Form_Load event.
I then said:
Try adding it to the form's New sub


So, open up the designer generated section (at the top of the code) and
make it look like this:

Public Sub New()
MyBase.New()

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

'Add any initialization after the InitializeComponent() call
Me.StartPosition = FormStartPosition.CenterScreen
End Sub
LFS

Nov 21 '05 #28
You can add your form2 to form1 owned forms collection using the
form1.AddOwnedForm method and then you will be able to reference form1 using
form2.Owner property.

As a result, if you minimize or close form1, form2 too will be minimized or
closed. Moreover, Form1 will always be behind Form2.

Bye!
"Cor Ligthert" <no************@planet.nl> ha scritto nel messaggio
news:e4*************@TK2MSFTNGP12.phx.gbl...
Geoff,

I find this question (I have seen it more) forever weird, therefore I am
curious for the reason you do it this way and not just use an almost
foerever hidded panel that you hide and make visible.

The only thing you have to think than about is that you set the Zorder of
the panel right.

However maybe you have a special reason for the form and I am curious for
that. Will you tell why?

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
Hi

Suppose I have two forms: Form1 and Form2. I create and show an instance
of
Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at
either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Can anybody help???

Thanks in advance

Geoff


Nov 21 '05 #29
You can add your form2 to form1 owned forms collection using the
form1.AddOwnedForm method and then you will be able to reference form1 using
form2.Owner property.

As a result, if you minimize or close form1, form2 too will be minimized or
closed. Moreover, Form1 will always be behind Form2.

Bye!
"Cor Ligthert" <no************@planet.nl> ha scritto nel messaggio
news:e4*************@TK2MSFTNGP12.phx.gbl...
Geoff,

I find this question (I have seen it more) forever weird, therefore I am
curious for the reason you do it this way and not just use an almost
foerever hidded panel that you hide and make visible.

The only thing you have to think than about is that you set the Zorder of
the panel right.

However maybe you have a special reason for the form and I am curious for
that. Will you tell why?

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
Hi

Suppose I have two forms: Form1 and Form2. I create and show an instance
of
Form2 in the code of Form1 e.g.

Dim myForm2 = New Form2
myForm2.Show()

How do I tell myForm2 that Form1 is its parent? That is, when I look at
either "Parent" or "ParentForm" in Form2, they both show "Nothing".

Can anybody help???

Thanks in advance

Geoff


Nov 21 '05 #30

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote
How do I make a form which is created in the first form, open up so that it
is centered on the first form? Okay, I know I could probably do the same
thing i.e. center it on the screen, but what if the first form is not
centered on the screen? I've tried setting the properties value of the
second form to:

FormStartPosition to CenterParent

but it doesn't work.

Any ideas?

Sure, how about you tell it to center itself on the parent form?

Public Overloads Sub Show(ByRef Parent As Form)
Dim center As Size = New Size((Parent.Width - Me.Width) \ 2, _
(Parent.Height - Me.Height) \ 2)

Me.StartPosition = FormStartPosition.Manual
Me.Location = Point.op_Addition(Parent.Location, center)
Me.TopMost = True
Me.Show()
End Sub
Add that to your second form, and call it from your first form like:

Dim f2 As New Form2
f2.Show(Me)

Easy enough? <g>
LFS

Nov 21 '05 #31

"Geoff Jones" <ge***@NODAMNSPAM.com> wrote
How do I make a form which is created in the first form, open up so that it
is centered on the first form? Okay, I know I could probably do the same
thing i.e. center it on the screen, but what if the first form is not
centered on the screen? I've tried setting the properties value of the
second form to:

FormStartPosition to CenterParent

but it doesn't work.

Any ideas?

Sure, how about you tell it to center itself on the parent form?

Public Overloads Sub Show(ByRef Parent As Form)
Dim center As Size = New Size((Parent.Width - Me.Width) \ 2, _
(Parent.Height - Me.Height) \ 2)

Me.StartPosition = FormStartPosition.Manual
Me.Location = Point.op_Addition(Parent.Location, center)
Me.TopMost = True
Me.Show()
End Sub
Add that to your second form, and call it from your first form like:

Dim f2 As New Form2
f2.Show(Me)

Easy enough? <g>
LFS

Nov 21 '05 #32

"Larry Serflaten" <se*******@usinternet.com> wrote
Me.StartPosition = FormStartPosition.Manual
Me.Location = Point.op_Addition(Parent.Location, center)
Me.TopMost = True
Me.Show()

Or, as Marco suggested, you could get the functionality he mentioned
substituting the TopMost line with this:

' Me.TopMost = True
Parent.AddOwnedForm(Me)

LFS
Nov 21 '05 #33

"Larry Serflaten" <se*******@usinternet.com> wrote
Me.StartPosition = FormStartPosition.Manual
Me.Location = Point.op_Addition(Parent.Location, center)
Me.TopMost = True
Me.Show()

Or, as Marco suggested, you could get the functionality he mentioned
substituting the TopMost line with this:

' Me.TopMost = True
Parent.AddOwnedForm(Me)

LFS
Nov 21 '05 #34
Geoff,

The missing points in my message are given by Marco, the way to do it is in
my opinion the same as in my message, however the reference method is
better. However, more important, the lack in my anser is that it can become
behind the owner. I knew this (had readed this before) however it did not
reach my front partition.

Cor

"Cor Ligthert" <no************@planet.nl>
Geoff,

Is it not that your idea of a parent is not what a parent is.
http://msdn.microsoft.com/library/de...arenttopic.asp

When you want to center it to the screen, than it is in my opinion
calculating the point to screen from what you call your parent form and
set that in your child form.

When you want to set a reference do it in the same way as you said you do
it in C++ only here it is named. Me.

\\\
Private Sub Button1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim frm As New Form2
frm.Text = "geoff"
frm.Height = Me.Height - 100
frm.Width = Me.Width - 100
Me.Location = New Drawing.Point _
(Me.Location.X + 50, Me.Location.Y + 50)
frm.parentform = Me 'the C this pointer and created as property on
Form2
' with this a reference is created to the mainform on the subform
frm.Show()
End Sub.
///
In my idea do you focus to much on the existing parent property, while it
is in my idea possible as well on the "child", just referencing the "me"
from the by you created"parentform" on your child form.

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
Hi Cor

You're idea of using an forever hidden panel is interesting. I may give
it a
go.

However, I am still puzzled why my code is not working. Being from a C++
background, I'm trying to understand VB.net and I can't understand why
CenterParent does not work. This, as with most things, has made me ask
some
other questions as you have seen. For example, how do I tell Form2 that
Form1 is the calling routine i.e. it is the parent. I would have thought
it
would have implicitly passed a pointer to Form2 to say that Form1 was the
parent. If it doesn't, how do I pass a pointer to Form2 to tell it that
Form
1 is a pointer i.e. in C++ I would have passed a "this" pointer
explicitly.

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e4*************@TK2MSFTNGP12.phx.gbl...
Geoff,

I find this question (I have seen it more) forever weird, therefore I am
curious for the reason you do it this way and not just use an almost
foerever hidded panel that you hide and make visible.

The only thing you have to think than about is that you set the Zorder
of
the panel right.

However maybe you have a special reason for the form and I am curious
for
that. Will you tell why?

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
> Hi
>
> Suppose I have two forms: Form1 and Form2. I create and show an
> instance
> of
> Form2 in the code of Form1 e.g.
>
> Dim myForm2 = New Form2
> myForm2.Show()
>
> How do I tell myForm2 that Form1 is its parent? That is, when I look
> at
> either "Parent" or "ParentForm" in Form2, they both show "Nothing".
>
> Can anybody help???
>
> Thanks in advance
>
> Geoff
>
>



Nov 21 '05 #35
Geoff,

The missing points in my message are given by Marco, the way to do it is in
my opinion the same as in my message, however the reference method is
better. However, more important, the lack in my anser is that it can become
behind the owner. I knew this (had readed this before) however it did not
reach my front partition.

Cor

"Cor Ligthert" <no************@planet.nl>
Geoff,

Is it not that your idea of a parent is not what a parent is.
http://msdn.microsoft.com/library/de...arenttopic.asp

When you want to center it to the screen, than it is in my opinion
calculating the point to screen from what you call your parent form and
set that in your child form.

When you want to set a reference do it in the same way as you said you do
it in C++ only here it is named. Me.

\\\
Private Sub Button1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim frm As New Form2
frm.Text = "geoff"
frm.Height = Me.Height - 100
frm.Width = Me.Width - 100
Me.Location = New Drawing.Point _
(Me.Location.X + 50, Me.Location.Y + 50)
frm.parentform = Me 'the C this pointer and created as property on
Form2
' with this a reference is created to the mainform on the subform
frm.Show()
End Sub.
///
In my idea do you focus to much on the existing parent property, while it
is in my idea possible as well on the "child", just referencing the "me"
from the by you created"parentform" on your child form.

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
Hi Cor

You're idea of using an forever hidden panel is interesting. I may give
it a
go.

However, I am still puzzled why my code is not working. Being from a C++
background, I'm trying to understand VB.net and I can't understand why
CenterParent does not work. This, as with most things, has made me ask
some
other questions as you have seen. For example, how do I tell Form2 that
Form1 is the calling routine i.e. it is the parent. I would have thought
it
would have implicitly passed a pointer to Form2 to say that Form1 was the
parent. If it doesn't, how do I pass a pointer to Form2 to tell it that
Form
1 is a pointer i.e. in C++ I would have passed a "this" pointer
explicitly.

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e4*************@TK2MSFTNGP12.phx.gbl...
Geoff,

I find this question (I have seen it more) forever weird, therefore I am
curious for the reason you do it this way and not just use an almost
foerever hidded panel that you hide and make visible.

The only thing you have to think than about is that you set the Zorder
of
the panel right.

However maybe you have a special reason for the form and I am curious
for
that. Will you tell why?

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
> Hi
>
> Suppose I have two forms: Form1 and Form2. I create and show an
> instance
> of
> Form2 in the code of Form1 e.g.
>
> Dim myForm2 = New Form2
> myForm2.Show()
>
> How do I tell myForm2 that Form1 is its parent? That is, when I look
> at
> either "Parent" or "ParentForm" in Form2, they both show "Nothing".
>
> Can anybody help???
>
> Thanks in advance
>
> Geoff
>
>



Nov 21 '05 #36
Many thank Cor (and all others who helped)

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:Ou**************@TK2MSFTNGP15.phx.gbl...
Geoff,

The missing points in my message are given by Marco, the way to do it is in my opinion the same as in my message, however the reference method is
better. However, more important, the lack in my anser is that it can become behind the owner. I knew this (had readed this before) however it did not
reach my front partition.

Cor

"Cor Ligthert" <no************@planet.nl>
Geoff,

Is it not that your idea of a parent is not what a parent is.
http://msdn.microsoft.com/library/de...arenttopic.asp
When you want to center it to the screen, than it is in my opinion
calculating the point to screen from what you call your parent form and
set that in your child form.

When you want to set a reference do it in the same way as you said you do it in C++ only here it is named. Me.

\\\
Private Sub Button1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim frm As New Form2
frm.Text = "geoff"
frm.Height = Me.Height - 100
frm.Width = Me.Width - 100
Me.Location = New Drawing.Point _
(Me.Location.X + 50, Me.Location.Y + 50)
frm.parentform = Me 'the C this pointer and created as property on Form2
' with this a reference is created to the mainform on the subform
frm.Show()
End Sub.
///
In my idea do you focus to much on the existing parent property, while it is in my idea possible as well on the "child", just referencing the "me"
from the by you created"parentform" on your child form.

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
Hi Cor

You're idea of using an forever hidden panel is interesting. I may give
it a
go.

However, I am still puzzled why my code is not working. Being from a C++ background, I'm trying to understand VB.net and I can't understand why
CenterParent does not work. This, as with most things, has made me ask
some
other questions as you have seen. For example, how do I tell Form2 that
Form1 is the calling routine i.e. it is the parent. I would have thought it
would have implicitly passed a pointer to Form2 to say that Form1 was the parent. If it doesn't, how do I pass a pointer to Form2 to tell it that
Form
1 is a pointer i.e. in C++ I would have passed a "this" pointer
explicitly.

Geoff

"Cor Ligthert" <no************@planet.nl> wrote in message
news:e4*************@TK2MSFTNGP12.phx.gbl...
Geoff,

I find this question (I have seen it more) forever weird, therefore I am curious for the reason you do it this way and not just use an almost
foerever hidded panel that you hide and make visible.

The only thing you have to think than about is that you set the Zorder
of
the panel right.

However maybe you have a special reason for the form and I am curious
for
that. Will you tell why?

Cor

"Geoff Jones" <ge***@NODAMNSPAM.com>
> Hi
>
> Suppose I have two forms: Form1 and Form2. I create and show an
> instance
> of
> Form2 in the code of Form1 e.g.
>
> Dim myForm2 = New Form2
> myForm2.Show()
>
> How do I tell myForm2 that Form1 is its parent? That is, when I look
> at
> either "Parent" or "ParentForm" in Form2, they both show "Nothing".
>
> Can anybody help???
>
> Thanks in advance
>
> Geoff
>
>



Nov 21 '05 #37
Many thanks Larry, it worked a treat!

Geoff

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:OF**************@TK2MSFTNGP11.phx.gbl...

"Larry Serflaten" <se*******@usinternet.com> wrote
Me.StartPosition = FormStartPosition.Manual
Me.Location = Point.op_Addition(Parent.Location, center)
Me.TopMost = True
Me.Show()

Or, as Marco suggested, you could get the functionality he mentioned
substituting the TopMost line with this:

' Me.TopMost = True
Parent.AddOwnedForm(Me)

LFS

Nov 21 '05 #38

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

Similar topics

25
by: Steve Jorgensen | last post by:
Yup, Steve's full of tips, but hey, it makes him feel important, right? Ok, here goes. I've been trying to improve encapsulation by putting code in the same object as the stuff it affects, so I...
13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
3
by: David N | last post by:
Hi All, I just wonder if in C#, I can develop a user defined control that can call its parent function which is not yet developed. For example, how do I make my user control call a...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
12
by: Tom W | last post by:
What's the difference in these three?
3
by: Eddie | last post by:
If FormMain = MDI parent, FormSub = Child parent, I execute FormSub from the menu like this way. FormSub^ sub = gcnew FormSub; sub->MdiParent = this; sub->Show(); This can generate child...
4
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if...
1
by: Richard | last post by:
Greetings. I am total newbie to Javascript so what is written below is probably a bunch of cobblers!! Any assistance in correcting my code much appreciated. I wish the popped up child to pass...
1
by: IframeLearner | last post by:
Hi , I am trying to upload a file from a parent.jsp using Iframes. From Parent page. I have to save Subject, Desc, File and file name. to upload the file i am using Iframe. I want the...
3
by: O.B. | last post by:
I have a form that shows another child form using the Show() operation. Since the child is modaless, I would like the option that when I click anywhere on the parent form that the parent form...
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: 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
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
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,...

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.