确定对象是否为文本框 [英] determin if a object is a textbox
本文介绍了确定对象是否为文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在wpf c#windows app中,如何确定控件是否为texbox?
void测试(对象发送者)
{
if(sender == Texbox)
{
//做点什么。
}
}
谢谢。
-
mo ******* @ noemail.noem ail
in a wpf c# windows app, how do I determin if a control is a texbox?
void Test(object sender)
{
if(sender==Texbox)
{
// do something.
}
}
Thanks.
--
mo*******@noemail.noemail
推荐答案
当然文本框有价值更重要,为什么不只是
检查一下呢?最简单的方法是相应地命名对象
并在提交某个表单时检查对象名称,但是你可以使用这些代码中的代码检查TypeOf控件(不测试
介意你!!)。
Dim myControl As Control
Dim textBox As TextBox
每个myControl In Controls
如果TypeOf myControl是TextBox那么
textBox = CType(myControl,TextBox)
textBox.Text = 你好
结束如果
下一页
问候
John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
moondaddy < mo ******* @ noemail.noemailwrote in message
news:e0 **************** @ TK2MSFTNGP06.phx.gbl。 ..
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*******@noemail.noemailwrote in message
news:e0****************@TK2MSFTNGP06.phx.gbl...
在wpf c#windows app中,如何确定控件是否为texbox?
void Test (对象发件人)
{
if(sender == Texbox)
{
//做点什么。
}
}
谢谢。
-
mo ******* @ noemail.noem ail
in a wpf c# windows app, how do I determin if a control is a texbox?
void Test(object sender)
{
if(sender==Texbox)
{
// do something.
}
}
Thanks.
--
mo*******@noemail.noemail
void测试(对象发送者)
{
if(sender.getType.name ==" Texbox")
{
//做点什么。
}
}
" moondaddy" < mo ******* @ noemail.noemailwrote in message
news:e0 **************** @ TK2MSFTNGP06.phx.gbl。 ..
void Test(object sender)
{
if(sender.getType.name == "Texbox")
{
// do something.
}
}
"moondaddy" <mo*******@noemail.noemailwrote in message
news:e0****************@TK2MSFTNGP06.phx.gbl...
在wpf c#windows app中,如何确定控件是否为texbox?
void Test (对象发送者)
{
if(sender == Texbox)
{
//做点什么。
}
}
谢谢。
-
mo ******* @ noemail.noem ail
in a wpf c# windows app, how do I determin if a control is a texbox?
void Test(object sender)
{
if(sender==Texbox)
{
// do something.
}
}
Thanks.
--
mo*******@noemail.noemail
文本框具有其他控件可能没有的属性和方法,如果OP想要调用文本框所特有的属性,则需要
,他/她会
$实际上,b $ b必须知道发件人是否是一个文本框,然后再将其转换为一个文本框。
John Timney(MVP) < x _ **** @ timney.eclipse.co.ukwrote in message
news:Pp ********************* @ eclipse.net.uk ...
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.ukwrote in message
news:Pp*********************@eclipse.net.uk...
肯定更重要的是文本框有一个值,为什么不只是
检查一下?最简单的方法是相应地命名对象
并在提交某个表单时检查对象名称,但是你可以使用这些代码中的代码检查TypeOf控件(不是
测试介意你!!)。
Dim myControl As Control
Dim textBox As TextBox
每个myControl In Controls
如果TypeOf myControl是TextBox那么
textBox = CType(myControl,TextBox)
textBox.Text = 你好
结束如果
下一页
问候
John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
moondaddy < mo ******* @ noemail.noemailwrote in message
news:e0 **************** @ TK2MSFTNGP06.phx.gbl。 ..
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*******@noemail.noemailwrote in message
news:e0****************@TK2MSFTNGP06.phx.gbl...
>在一个wpf c #windows app中,我该如何判断一个控件是否是一个texbox?
void测试(对象)发件人)
{
if(sender == Texbox)
{
//做点什么。
}
}
谢谢。
-
mo*******@noemail.noem
这篇关于确定对象是否为文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文