Solved

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

Posted on 2008-10-22
6
528 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

809 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