473,779 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9498
sh*******@hotma il.com (CJack) wrote in news:2e52a6a3.0 310251301.27521 6a0
@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&snusn u.at> wrote in message
news:u9******** ******@TK2MSFTN GP12.phx.gbl...
sh*******@hotma il.com (CJack) wrote in news:2e52a6a3.0 310251301.27521 6a0
@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.WriteLi ne("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
2889
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 that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
3
2221
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" name="MyImageButton" id="MyImageButton" src="somePic.jpg" /> I want for the code-behind to "know" when the user clicked on the image - but I don't want to also have to dynamically specify a delegate for an event procedure to handle this control which is really...
3
7441
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 seems to always return FALSE. Thanks. Tom
4
2703
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. Code shippet is as follows: if ( ActiveControl.GetType() == typeof(UltraTextEditor)) { UltraTextEditor tb = (UltraTextEditor) this.ActiveControl; if (tb.Multiline == true)
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9930
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.