473,788 Members | 2,814 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 2516
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
4461
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
2236
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
8105
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
1705
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
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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
10173
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
10110
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,...
1
7517
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
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.