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

Calling functions between panels in WinForms C#

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
2 2495
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marc Shapiro | last post by:
I am relatively new to python (I have used it on and off for a few small projects over the last few years) so I imagine that what I am trying to do has already been done, but practical experience,...
5
by: Dave | last post by:
does calling a regular function cost any cpu time? In other words, is it faster to write the code of two functions into main(), or is it the exact same thing as calling two functions. I know its...
4
by: BBM | last post by:
I'm trying to set up a form with two panels divided by a Splitter control. I can make the Splitter work in the situations described in the documentation (Listbox or TreeView on left w/Dock set to...
1
by: Greg Busby | last post by:
I am a newbie to ASP.NET and webservices. I have a webservice that is calling a C# dll. This dll then calls methods in a VB COM+ component. The COM+ component is not instantiating correctly. The...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.