Solved

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

Posted on 2008-10-22
6
526 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now