473,396 Members | 1,996 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,396 software developers and data experts.

Determine control type

hi, i have a window form with different controls. i want to loop
through all the controls and write the types and lables of each
control in a file. I dnt know how to determine the type of a control
that wether it is a button, lable or text box.
any body out there to help please.

thanks in advance
Nov 15 '05 #1
2 9468
sh*******@hotmail.com (CJack) wrote in news:2e52a6a3.0310251301.275216a0
@posting.google.com:
hi, i have a window form with different controls. i want to loop
through all the controls and write the types and lables of each
control in a file. I dnt know how to determine the type of a control
that wether it is a button, lable or text box.
any body out there to help please.

thanks in advance


foreach(Control c in Controls)
{
Button b = c as Button;
if(n!=null)
{
//Button code
return;
}

TextBox tb = c as TextBox;
if(tb!=null)
{
//TextBox code
return;
}
}

--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Nov 15 '05 #2
TB
"Peter Koen" <koen-newsreply&snusnu.at> wrote in message
news:u9**************@TK2MSFTNGP12.phx.gbl...
sh*******@hotmail.com (CJack) wrote in news:2e52a6a3.0310251301.275216a0
@posting.google.com:
hi, i have a window form with different controls. i want to loop
through all the controls and write the types and lables of each
control in a file. I dnt know how to determine the type of a control
that wether it is a button, lable or text box.
any body out there to help please.

thanks in advance


foreach(Control c in Controls)
{
Button b = c as Button;
if(n!=null)
{
//Button code
return;
}

TextBox tb = c as TextBox;
if(tb!=null)
{
//TextBox code
return;
}
}

--


Just use object.GetType() and Control.Text to get the system type of each
control and its label.

e.g.
foreach (Control c in Controls)
{
Console.WriteLine("Control Type = {0}, Label = {1}",
c.GetType(),
c.Text);
}

Since all controls have the Text property, there is no need to coerce the
controls to their specific type.

However, if you do need to then the above code certainly does the trick.
Likewise you can use the "is" keyword if you don't actually need to operate
on the control.

if (c is Button)
// Special case for Button controls

-- TB
Nov 15 '05 #3

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

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
3
by: Jordan | last post by:
I am dynamically inserting an html <input> tag as text (equivalent of an image button) into a page via a Literal control. Something like this gets inserted: <input type="image"...
3
by: Tom | last post by:
This is probably pretty easy, but how does one determine if a control is a CONTAINER control? I thought something like If Typeof myControl is ContainerControl then .... would work but that...
4
by: Bill Fuller | last post by:
I am trying to determine the type for ActiveControls using 3rd party controls (Infragistics in this case) during runtime and getting a rather odd return type at runtime for the UltraWinEditor. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.