Solved

How do I reference form controls for a seperate class (c#)?

Posted on 2008-10-22
6
529 Views
Last Modified: 2012-06-27
Assume I have a windows for with only 1 control... a Panel named panel1. I have a seperate class that I want to run that adds a control (an activex control specifically but I dont think that matters) onto panel1. I have found various ways to reference control values... but I have found no solutions as to how I reference the panel1 control specifically so I can add my activeX control to it from a seperate class.
0
Comment
Question by:Pretzel_Jesus
6 Comments
 
LVL 8

Expert Comment

by:jorgesv13
ID: 22780114
You can add the control to the ControlsCollection of the Panel, like this:

Panel pn = Form1.Panel1;
pn.Controls.Add(MyControl);
0
 

Author Comment

by:Pretzel_Jesus
ID: 22780156
I tried that and when I use the intellisense for Form1. all I see are some delegates I have I dont see any controls...
0
 
LVL 6

Expert Comment

by:RishadanPort
ID: 22780192
>all I see are some delegates I have I dont see any controls...

What do you mean all you see are some delegates but not any controls?
When you added the object, and run the program, does the ActiveX control show or not?
Make sure that the ActiveX control's Visible property is set to true.
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 6

Expert Comment

by:RishadanPort
ID: 22780220
In order to get back the ActiveX control that you added you need to do something like this:

(suppose ActiveXControl is your class name)

ActiveXControl myActiveX = null;

foreach(Control contr in panel1.Controls)
{
   if(contr is ActiveXControl){
      myActiveX = (ActiveXControl)contr;
   }
}

if(myActiveX == null){
   throw new Exception("ActiveX Control was not found in panel1");
}
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 200 total points
ID: 22780242
Change the MODIFIERS() property for your controls to Public if you want to be able to see them from outside your class...

0
 
LVL 8

Accepted Solution

by:
jorgesv13 earned 300 total points
ID: 22780266
You can try:
1. Make sure the panel access modifier is set to "Public" (default is Friend)
2. Are you instantiating the Form? Like:
Form1 frm = new Form1;
frm.panel1.controls.add(MyActiveXControl);
frm.ShowDialog()
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question