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

Calling functions between panels in WinForms C#

P: n/a
I'm working in Visual Studio 2005 and C#.

I have a WinForms application with two panels (left panel and right panel).
I have a textbox on the left panel, and a button on the right panel. I'd like
to have a button-press from the right panel call a function in the left
panel, which might simply Console.Writeline(textBox1.Text);

If I could get the instance of the PanelLeft class, I could simply say:

panelLeftInstance.PrintTextToConsole();

The problem is I don't see how to get an instance of the PanelLeft class. I
placed the PanelLeft and PanelRight panels onto the WinForm from the toolbox.

Thanks,
Randy
Feb 16 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
randy,

From what I see you have derived your onwn classes from the Panel class and
handle button click event inside this custom panel. In this case you need to
provide the second panel with the reference to the first panel. Other
solution would be the form to expose those panels as public properties and
then inside the second panel you can find the form - FindForm method, cast
it to your form class and use these properties.

However both solution so far make classes tightly coupled. Better would be
the second panel to fire an event when the button is clicked and let the
form call the method on the first panel. This way both panels know squat
about each other and the parent container.
--
HTH
Stoitcho Goutsev (100)

"randy1200" <ra*******@newsgroups.nospam> wrote in message
news:DA**********************************@microsof t.com...
I'm working in Visual Studio 2005 and C#.

I have a WinForms application with two panels (left panel and right
panel).
I have a textbox on the left panel, and a button on the right panel. I'd
like
to have a button-press from the right panel call a function in the left
panel, which might simply Console.Writeline(textBox1.Text);

If I could get the instance of the PanelLeft class, I could simply say:

panelLeftInstance.PrintTextToConsole();

The problem is I don't see how to get an instance of the PanelLeft class.
I
placed the PanelLeft and PanelRight panels onto the WinForm from the
toolbox.

Thanks,
Randy

Feb 16 '06 #2

P: n/a
Why didn't I think of that? <ggg> That's exactly what I needed. Many thanks.
--
Randy
"Stoitcho Goutsev (100)" wrote:
randy,

From what I see you have derived your onwn classes from the Panel class and
handle button click event inside this custom panel. In this case you need to
provide the second panel with the reference to the first panel. Other
solution would be the form to expose those panels as public properties and
then inside the second panel you can find the form - FindForm method, cast
it to your form class and use these properties.

However both solution so far make classes tightly coupled. Better would be
the second panel to fire an event when the button is clicked and let the
form call the method on the first panel. This way both panels know squat
about each other and the parent container.
--
HTH
Stoitcho Goutsev (100)

"randy1200" <ra*******@newsgroups.nospam> wrote in message
news:DA**********************************@microsof t.com...
I'm working in Visual Studio 2005 and C#.

I have a WinForms application with two panels (left panel and right
panel).
I have a textbox on the left panel, and a button on the right panel. I'd
like
to have a button-press from the right panel call a function in the left
panel, which might simply Console.Writeline(textBox1.Text);

If I could get the instance of the PanelLeft class, I could simply say:

panelLeftInstance.PrintTextToConsole();

The problem is I don't see how to get an instance of the PanelLeft class.
I
placed the PanelLeft and PanelRight panels onto the WinForm from the
toolbox.

Thanks,
Randy


Feb 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.