in a wpf c# windows app, how do I determin if a control is a texbox?
void Test(object sender)
{
if(sender==Texb ox)
{
// do something.
}
}
Thanks.
-- mo*******@noema il.noemail 10 5957
Surely its more important that the textbox has a value, why dont you just
check that instead? The easiest way would be to name the objects
accordingly and check the object name at submission of some form, but you
can probably check the TypeOf control using code along these lines (not test
mind you!!).
Dim myControl As Control
Dim textBox As TextBox
For Each myControl In Controls
If TypeOf myControl Is TextBox Then
textBox = CType(myControl , TextBox)
textBox.Text = "Hello"
End If
Next
Regards
John Timney (MVP) http://www.johntimney.com http://www.johntimney.com/blog
"moondaddy" <mo*******@noem ail.noemailwrot e in message
news:e0******** ********@TK2MSF TNGP06.phx.gbl. ..
in a wpf c# windows app, how do I determin if a control is a texbox?
void Test(object sender)
{
if(sender==Texb ox)
{
// do something.
}
}
Thanks.
-- mo*******@noema il.noemail
void Test(object sender)
{
if(sender.getTy pe.name == "Texbox")
{
// do something.
}
}
"moondaddy" <mo*******@noem ail.noemailwrot e in message
news:e0******** ********@TK2MSF TNGP06.phx.gbl. ..
in a wpf c# windows app, how do I determin if a control is a texbox?
void Test(object sender)
{
if(sender==Texb ox)
{
// do something.
}
}
Thanks.
-- mo*******@noema il.noemail
Textboxes have properties and methods that other controls may not have and
if the OP wants to call a property that is unique to textboxes, he/she would
have to know if the sender is, in fact, a textbox before casting it to one.
"John Timney (MVP)" <x_****@timney. eclipse.co.ukwr ote in message
news:Pp******** *************@e clipse.net.uk.. .
Surely its more important that the textbox has a value, why dont you just
check that instead? The easiest way would be to name the objects
accordingly and check the object name at submission of some form, but you
can probably check the TypeOf control using code along these lines (not
test mind you!!).
Dim myControl As Control
Dim textBox As TextBox
For Each myControl In Controls
If TypeOf myControl Is TextBox Then
textBox = CType(myControl , TextBox)
textBox.Text = "Hello"
End If
Next
Regards
John Timney (MVP) http://www.johntimney.com http://www.johntimney.com/blog
"moondaddy" <mo*******@noem ail.noemailwrot e in message
news:e0******** ********@TK2MSF TNGP06.phx.gbl. ..
>in a wpf c# windows app, how do I determin if a control is a texbox?
void Test(object sender) { if(sender==Texb ox) { // do something. } }
Thanks. -- mo*******@noema il.noemail
Indeed they do - good suggestion - not considered that in my reply!
Regards
John Timney (MVP) http://www.johntimney.com http://www.johntimney.com/blog
"Scott M." <s-***@nospam.nosp amwrote in message
news:en******** ******@TK2MSFTN GP06.phx.gbl...
Textboxes have properties and methods that other controls may not have and
if the OP wants to call a property that is unique to textboxes, he/she
would have to know if the sender is, in fact, a textbox before casting it
to one.
"John Timney (MVP)" <x_****@timney. eclipse.co.ukwr ote in message
news:Pp******** *************@e clipse.net.uk.. .
>Surely its more important that the textbox has a value, why dont you just check that instead? The easiest way would be to name the objects accordingly and check the object name at submission of some form, but you can probably check the TypeOf control using code along these lines (not test mind you!!).
Dim myControl As Control Dim textBox As TextBox For Each myControl In Controls If TypeOf myControl Is TextBox Then textBox = CType(myControl , TextBox) textBox.Text = "Hello" End If Next Regards
John Timney (MVP) http://www.johntimney.com http://www.johntimney.com/blog
"moondaddy" <mo*******@noem ail.noemailwrot e in message news:e0******* *********@TK2MS FTNGP06.phx.gbl ...
>>in a wpf c# windows app, how do I determin if a control is a texbox?
void Test(object sender) { if(sender==Texb ox) { // do something. } }
Thanks. -- mo*******@noema il.noemail
Great thanks guys! This is what I need and yes Scott, I do need to know
what type of control it is first and at this point I'm not concerned with
the value in the control, just it's type.
"Scott M." <s-***@nospam.nosp amwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
void Test(object sender)
{
if(sender.getTy pe.name == "Texbox")
{
// do something.
}
}
"moondaddy" <mo*******@noem ail.noemailwrot e in message
news:e0******** ********@TK2MSF TNGP06.phx.gbl. ..
>in a wpf c# windows app, how do I determin if a control is a texbox?
void Test(object sender) { if(sender==Texb ox) { // do something. } }
Thanks. -- mo*******@noema il.noemail
I get a compile error on getType. sender (object) doesnt contain a
definitin for getttype. Any other ideas?
"Scott M." <s-***@nospam.nosp amwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
void Test(object sender)
{
if(sender.getTy pe.name == "Texbox")
{
// do something.
}
}
"moondaddy" <mo*******@noem ail.noemailwrot e in message
news:e0******** ********@TK2MSF TNGP06.phx.gbl. ..
>in a wpf c# windows app, how do I determin if a control is a texbox?
void Test(object sender) { if(sender==Texb ox) { // do something. } }
Thanks. -- mo*******@noema il.noemail
This is it:
sender.GetType( ).Name
"moondaddy" <mo*******@noem ail.noemailwrot e in message
news:OO******** ******@TK2MSFTN GP02.phx.gbl...
>I get a compile error on getType. sender (object) doesnt contain a definitin for getttype. Any other ideas?
"Scott M." <s-***@nospam.nosp amwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>void Test(object sender) { if(sender.getTy pe.name == "Texbox") { // do something. } } "moondaddy" <mo*******@noem ail.noemailwrot e in message news:e0******* *********@TK2MS FTNGP06.phx.gbl ...
>>in a wpf c# windows app, how do I determin if a control is a texbox?
void Test(object sender) { if(sender==Texb ox) { // do something. } }
Thanks. -- mo*******@noema il.noemail
GetType()
C-Sharp is case senstive langugae
VJ
"moondaddy" <mo*******@noem ail.noemailwrot e in message
news:OO******** ******@TK2MSFTN GP02.phx.gbl...
>I get a compile error on getType. sender (object) doesnt contain a definitin for getttype. Any other ideas?
"Scott M." <s-***@nospam.nosp amwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>void Test(object sender) { if(sender.getTy pe.name == "Texbox") { // do something. } } "moondaddy" <mo*******@noem ail.noemailwrot e in message news:e0******* *********@TK2MS FTNGP06.phx.gbl ...
>>in a wpf c# windows app, how do I determin if a control is a texbox?
void Test(object sender) { if(sender==Texb ox) { // do something. } }
Thanks. -- mo*******@noema il.noemail
Scott M. <s-***@nospam.nosp amwrote:
void Test(object sender)
{
if(sender.getTy pe.name == "Texbox")
{
// do something.
}
}
That's a really bad way of checking it - not only does it rely on
comparing with a literal string, which can easily have a typo in (as
indeed your sample does), but it's also slower than using the operators
which C# already has - "is" and "as".
You can use:
if (sender is TextBox)
{
...
}
or:
TextBox textBox = sender as TextBox;
if (textBox != null)
{
...
}
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Laurence Nixon |
last post by:
Hello all.
I am seeking ideas on how to determin a specific value with varied
parameters.
This will be for students who have taken modules in a course for
pre-certification. So it will be like this:
StudentA
ModuleA + ModuleC + ModuleD + ModuleE = (Completetion of this COURSE1)
|
by: Magnabyte |
last post by:
Hello all.
I am seeking ideas on how to determin a specific value with varied
parameters.
This will be for students who have taken modules in a course for
pre-certification. So it will be like this:
StudentA
ModuleA + ModuleC + ModuleD + ModuleE = (Completetion of this COURSE1)
|
by: Kevin Phifer |
last post by:
Ok, before anyone freaks out, I have a solution I need to
create that gathers content from maybe different places.
Each one can return a <form> in the html, so its the
classic can't have more than one runat=server form on a
asp.net page. However, I still want developers to be able
to use asp.net controls to create some apps that are
created on the page. So I need multiple forms on a
asp.net page(doesn't everyone). I purchased the...
|
by: feng |
last post by:
I want to use onunload to capture user's action when he
clicks on the "x" button, the close window button on the
upper-right corner of the brower window, to close the
browser. Here is how I capture the event:
<SCRIPT FOR="window" EVENT="onunload">
myScript();
</SCRIPT>
While myScript() does get called when "x" gets clicked, it
is also get called when the user leaves the current page
|
by: Tancev Sasa |
last post by:
I am interesting how to determin is the selected printer a dot-matrix
printer or is it a laser printer
What property is relevant to detrmin what type is selected printer
| |
by: Alex |
last post by:
Dear colleagues
How can I determin if "return button was pressed" in a textbox? I am trying
to di this with this methode:
Private Sub txbInput_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txbInput.KeyDown
>> if (return was pressed then execute the follwoinf call
GetMembers()
|
by: jakobsg |
last post by:
Hi. How can I determin the hwaddr or ipaddress of the networkinterface
that is used in an outgoing connection? I need a kind of traceroute in
python or lowlevel socket function that can help me find out which one
of my hosts networkinterfaces that is actually used or going to be used
to reach a certain remote host. Can I do this?
|
by: aProgrammingStudent |
last post by:
Here's the deal. I am creating a calculator program using visual studios. I have a much of buttons on my form and I want to be able to determin which button is clicked by the user.
Reason: I want to use the Text property of the botton pressed by the user without have to have a click event for each button.
|
by: Nick |
last post by:
Hi there,
Is it possible to tell how a WebMethod was invoked? For example I would
like to determin if it was invoked via SOAP or HTTP Post. Other than
creating 2 methods I am no sure if I can do this.
Many thanks for your time.
Nick.
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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,...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |