473,388 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Setting a control

I have a function that I can't seem to get to work properly. This function
is suppose to loop through a collection of controls and locate an existing
ojbect of that type. if it locates the control it uses that object if it
does not a new object is added.

public void SetMainControl(System.Windows.Forms.Control Testcontrol)

{

System.Windows.Forms.Control aTmpControl = TestControl;

bool found = false;

foreach(System.Windows.Forms.Control aControl in
StudyViewer_Fill_Panel.Controls)

{

if (aControl is aTmpControl)

{

found = true;

TestControl = aControl;

break;

}

}

if (!found)

{
StudyViewer_Fill_Panel.Controls.Add(Testcontrol);

}

Testcontrol.Dock = DockStyle.Fill;
}
Nov 15 '05 #1
3 1134
L#
On Thu, 5 Feb 2004 14:45:55 -0800, "MFRASER"
<mf*****@henwoodenergy.com> wrote:
I have a function that I can't seem to get to work properly. This function
is suppose to loop through a collection of controls and locate an existing
ojbect of that type. if it locates the control it uses that object if it
does not a new object is added.


An example:

public class MyControl : Control
{
// implementation of your control
}

private void Form1_Load(object sender, System.EventArgs e)
{
// add your control to the controls collection
this.Controls.Add(new MyControl());

// loop through all controls on the form and check if it's a
// MyControl
foreach (Control c in this.Controls)
{
// method 1
if (c.GetType() == typeof(MyControl))
{
// it's a MyControl
}

// method 2
if (c is MyControl)
{
// it's a MyControl
}

}

}
--
Ludwig
mailto:ludwig_(nospamplease)stuyck@pandora(nospamp lease).be
Nov 15 '05 #2
That is what I thought but when I create a function to set the control
and pass in that control the code will not compile.

So If I changed your code to

An example:

public class MyControl : Control
{
// implementation of your control
}

private void Form1_Load(object sender, System.EventArgs e)
{
// add your control to the controls collection
//this.Controls.Add(new MyControl());
this.SetMainControl( new MyControl());
}
private void SetMainControl(System.Windows.Forms MyControl)
{
// loop through all controls on the form and check if it's a
// MyControl
foreach (Control c in this.Controls)
{
// method 1
if (c.GetType() == typeof(MyControl))
{
// it's a MyControl
}

// method 2
if (c is MyControl)
{
// it's a MyControl
}

}

}
}


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3
L#
On Thu, 05 Feb 2004 16:19:39 -0800, Fraser Michael
<mf*****@henwoodenergy.com> wrote:
That is what I thought but when I create a function to set the control
and pass in that control the code will not compile.


That's beause the parameter has to be a Control, like this:

private void SetMainControl(Control MyControl)
...

--
Ludwig
mailto:ludwig_(nospamplease)stuyck@pandora(nospamp lease).be
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: dixie | last post by:
I want to be able to set the font size and font type for text in a text box on a report using VBA. I wan't to be able to control it from a setting in a table. The problem is that I don't know the...
2
by: MLH | last post by:
A form named frmVehicleEntryForm has a number of textbox controls who's OnGotFocus property setting is an expression... =Change2Green() Change2Green() looks something like this... Dim MyControl...
6
by: Peter Krikelis | last post by:
Hi All, I am having a problem setting up input mode for serial communications. (Sorry about the long code post). The following code is what I use to set up my comm port.
4
by: Gill Smith | last post by:
After setting the web control text box enable property to FALSE makes the control to loose the data between round trip. I am making sure that the property - EnableViewState = TRUE. Same code...
3
by: Patrick | last post by:
I am dynamically creating TextArea and drop-down lists in ASP.NET using something like HtmlTextArea eachTextArea = new HtmlTextArea(); I tried to set the "name" of these TextAreas, etc. (e.g....
8
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
1
by: simon | last post by:
I have an unbound RTF2 control in an Access 2003 form which I set to show either unformatted text or else text with words and sentences highlighted. I do this by setting the PlainText property,...
7
by: Academic | last post by:
What are the different effects of the following two statements: C1.Cursor = Cursors.WaitCursor C1.Cursor.Current = Cursors.WaitCursor I believe the first replaces the entire C1.Cursor...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
0
by: RKT | last post by:
I have a DataGridView bound to an MS Access table. This is a single- user application. When the User is adding or editing a row, the User may click on a Control elsewhere. That Control has context...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.