Solved

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

Posted on 2008-10-22
6
532 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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 …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

719 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