Solved

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

Posted on 2008-10-22
6
530 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: 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!

 
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 86

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

Industry Leaders: 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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

737 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