By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,997 Members | 1,098 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,997 IT Pros & Developers. It's quick & easy.

UserControls and Panels

P: n/a
Hi,

I realize this is a very common problem, but even though I've scoured the
Internet for resources, I can't seem to solve this issue :|

I currently have a very simple application. It contains a a single main
dialog in which all user interaction occurs. The dialog consists of "views",
that is panels, which contain various controls. Only one panel is shown at a
time. When the user has finished working on one panel, the next should be
shown.

As you probably know, designing all the panels in the main dialog is a pain
as they lie on top of each other.
That's why I instead decided to use UserControls and use a single panel on
the main form as a placeholder.

When the application starts up, the following code is executed and the first
view is shown:

// 'mainPanel' is the placeholder on the main form
// 'View1' is the UserControl
mainPanel.Controls.Clear();
mainPanel.Controls.Add(new View1());

Now, when the user wishes to proceed to the next view, he presses, say, a
button on the view's form (not on the main form).

My question is, how does the view update the main form's panel? I know there
are properties to access the parent form from the UserControl, but so far
I've had no luck accessing the main form's panel :|

Thanks!
Mar 27 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
You can have better control if you put your Back and Next buttons on the
form. Here's a very good article that will give you an idea on how to
implement a Wizard in C#: http://www.differentpla.net/node/403
Mar 27 '06 #2

P: n/a
One of the easiest ways to solve this is to pass an instance of the main form
to the UserControl in its constructor , e.g.

MyView vw = new MyView(this);
......//control:
private Form _mainForm;
Public MyView (Form frm)
{
this._mainForm=frm;
}
Now you have an instance of the parent form right inside your control. Fun,
heh?
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Søren Dreijer" wrote:
Hi,

I realize this is a very common problem, but even though I've scoured the
Internet for resources, I can't seem to solve this issue :|

I currently have a very simple application. It contains a a single main
dialog in which all user interaction occurs. The dialog consists of "views",
that is panels, which contain various controls. Only one panel is shown at a
time. When the user has finished working on one panel, the next should be
shown.

As you probably know, designing all the panels in the main dialog is a pain
as they lie on top of each other.
That's why I instead decided to use UserControls and use a single panel on
the main form as a placeholder.

When the application starts up, the following code is executed and the first
view is shown:

// 'mainPanel' is the placeholder on the main form
// 'View1' is the UserControl
mainPanel.Controls.Clear();
mainPanel.Controls.Add(new View1());

Now, when the user wishes to proceed to the next view, he presses, say, a
button on the view's form (not on the main form).

My question is, how does the view update the main form's panel? I know there
are properties to access the parent form from the UserControl, but so far
I've had no luck accessing the main form's panel :|

Thanks!

Mar 27 '06 #3

P: n/a
This may not be of help, but you can use MDI frame as your main form and then
normal forms for the rest.

To go from one form to the next, close the current form, open the new form and
display it maximized.

Something like

private void OpenNewForm()
{
CloseCurrentForm();
newForm = new NewForm();
newForm.WindowState = FormWindowState.Maximized;
newForm.Show();
}

Søren Dreijer wrote:
Hi,

I realize this is a very common problem, but even though I've scoured the
Internet for resources, I can't seem to solve this issue :|

I currently have a very simple application. It contains a a single main
dialog in which all user interaction occurs. The dialog consists of "views",
that is panels, which contain various controls. Only one panel is shown at a
time. When the user has finished working on one panel, the next should be
shown.

As you probably know, designing all the panels in the main dialog is a pain
as they lie on top of each other.
That's why I instead decided to use UserControls and use a single panel on
the main form as a placeholder.

When the application starts up, the following code is executed and the first
view is shown:

// 'mainPanel' is the placeholder on the main form
// 'View1' is the UserControl
mainPanel.Controls.Clear();
mainPanel.Controls.Add(new View1());

Now, when the user wishes to proceed to the next view, he presses, say, a
button on the view's form (not on the main form).

My question is, how does the view update the main form's panel? I know there
are properties to access the parent form from the UserControl, but so far
I've had no luck accessing the main form's panel :|

Thanks!

Mar 27 '06 #4

P: n/a
Yeah, I know, but the point was not to have the buttons on the main form (as
in a wizard) but on the sub-forms instead.

"yogeshprabhu" <yo**********@discussions.microsoft.com> wrote in message
news:5E**********************************@microsof t.com...
You can have better control if you put your Back and Next buttons on the
form. Here's a very good article that will give you an idea on how to
implement a Wizard in C#: http://www.differentpla.net/node/403

Mar 27 '06 #5

P: n/a
Ah, why didn't I think of that! Easy and straightforward :|

Thanks a bunch :]

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:9B**********************************@microsof t.com...
One of the easiest ways to solve this is to pass an instance of the main
form
to the UserControl in its constructor , e.g.

MyView vw = new MyView(this);
.....//control:
private Form _mainForm;
Public MyView (Form frm)
{
this._mainForm=frm;
}
Now you have an instance of the parent form right inside your control.
Fun,
heh?
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Søren Dreijer" wrote:
Hi,

I realize this is a very common problem, but even though I've scoured the
Internet for resources, I can't seem to solve this issue :|

I currently have a very simple application. It contains a a single main
dialog in which all user interaction occurs. The dialog consists of
"views",
that is panels, which contain various controls. Only one panel is shown
at a
time. When the user has finished working on one panel, the next should be
shown.

As you probably know, designing all the panels in the main dialog is a
pain
as they lie on top of each other.
That's why I instead decided to use UserControls and use a single panel
on
the main form as a placeholder.

When the application starts up, the following code is executed and the
first
view is shown:

// 'mainPanel' is the placeholder on the main form
// 'View1' is the UserControl
mainPanel.Controls.Clear();
mainPanel.Controls.Add(new View1());

Now, when the user wishes to proceed to the next view, he presses, say, a
button on the view's form (not on the main form).

My question is, how does the view update the main form's panel? I know
there
are properties to access the parent form from the UserControl, but so far
I've had no luck accessing the main form's panel :|

Thanks!

Mar 27 '06 #6

P: n/a
Short follow-up question:
What is the preferred way to let the children forms gain access to the
placeholder panel on the main form? Should I allow direct access to the
variable (public scope) or should I instead make a couple of accessor
functions (excuse the C++ term) ?

"Søren Dreijer" <bl**@bluh.net> wrote in message
news:ub**************@TK2MSFTNGP11.phx.gbl...
Ah, why didn't I think of that! Easy and straightforward :|

Thanks a bunch :]

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:9B**********************************@microsof t.com...
One of the easiest ways to solve this is to pass an instance of the main
form
to the UserControl in its constructor , e.g.

MyView vw = new MyView(this);
.....//control:
private Form _mainForm;
Public MyView (Form frm)
{
this._mainForm=frm;
}
Now you have an instance of the parent form right inside your control.
Fun,
heh?
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Søren Dreijer" wrote:
Hi,

I realize this is a very common problem, but even though I've scoured
the
Internet for resources, I can't seem to solve this issue :|

I currently have a very simple application. It contains a a single main
dialog in which all user interaction occurs. The dialog consists of
"views",
that is panels, which contain various controls. Only one panel is shown
at a
time. When the user has finished working on one panel, the next should
be
shown.

As you probably know, designing all the panels in the main dialog is a
pain
as they lie on top of each other.
That's why I instead decided to use UserControls and use a single panel
on
the main form as a placeholder.

When the application starts up, the following code is executed and the
first
view is shown:

// 'mainPanel' is the placeholder on the main form
// 'View1' is the UserControl
mainPanel.Controls.Clear();
mainPanel.Controls.Add(new View1());

Now, when the user wishes to proceed to the next view, he presses, say,
a
button on the view's form (not on the main form).

My question is, how does the view update the main form's panel? I know
there
are properties to access the parent form from the UserControl, but so
far
I've had no luck accessing the main form's panel :|

Thanks!


Mar 27 '06 #7

P: n/a
On Mon, 27 Mar 2006 23:27:40 +0200, "Søren Dreijer" <bl**@bluh.net> wrote:
Short follow-up question:
What is the preferred way to let the children forms gain access to the
placeholder panel on the main form? Should I allow direct access to the
variable (public scope) or should I instead make a couple of accessor
functions (excuse the C++ term) ?

[snip]

Use Accessors (Properties) ;o)

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Mar 28 '06 #8

P: n/a
Yeah, I thought of that, but I wasn't sure how one does that when dealing
with, say, a panel. It's not like you do any assignment operations or
similar. You just use one of its methods or properties.

Thanks,

"Otis Mukinfus" <ph***@emailaddress.com> wrote in message
news:kd********************************@4ax.com...
On Mon, 27 Mar 2006 23:27:40 +0200, "Søren Dreijer" <bl**@bluh.net> wrote:
Short follow-up question:
What is the preferred way to let the children forms gain access to the
placeholder panel on the main form? Should I allow direct access to the
variable (public scope) or should I instead make a couple of accessor
functions (excuse the C++ term) ?

[snip]

Use Accessors (Properties) ;o)

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com

Mar 28 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.