473,686 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Writeli ne(textBox1.Tex t);

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

panelLeftInstan ce.PrintTextToC onsole();

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 2510
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*******@news groups.nospam> wrote in message
news:DA******** *************** ***********@mic rosoft.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.Writeli ne(textBox1.Tex t);

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

panelLeftInstan ce.PrintTextToC onsole();

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*******@news groups.nospam> wrote in message
news:DA******** *************** ***********@mic rosoft.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.Writeli ne(textBox1.Tex t);

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

panelLeftInstan ce.PrintTextToC onsole();

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
4453
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, even if it is reinventing the wheel, is still useful, so... I am trying to write a module to handle drop down menus using curses (on linux). Curses seems to have a wrapper for the panels library, but not forms, or menus. I am not even sure...
5
2226
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 nitty gritty but its necessary for my program. thanks dave
4
8096
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 Left, Panel on right of form w/ Dock set to Fill, Splitter between them set w/ Dock set to Left. Works as advertised. But... if I change to have two panels on the form one on the left with Dock set to Left, a panel on the right with Dock set to...
1
1698
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 return value of the called function is an ADO recordset. Looking at the value of the variable in the watch window, it is undeclared. So, the function is not completing. I ran this code from a straight WinForms application and it worked fine. ...
0
8520
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9057
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8936
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8772
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8780
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7603
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6442
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.