主题:如何判断Textbox是否获取了焦点
xkonlyone
[专家分:0] 发布于 2005-09-17 17:14:00
运行环境:winXP
开发软件:Microsoft Visual Studio .NET 2003
开发语言:VB.NET
问题:往窗体上拖放Textbox1、Textbox2和Button1,Textbox1.text和Textbox2.text
为空,Button.text为0。如何编一段代码当Textbox1获取焦点时,单击
Button1,Textbox1.text赋值为1。当Textbox2获取焦点时,单击Button1,
Textbox2.text赋值为1。希望高手能提供正确代码。在此先谢过!!
回复列表 (共5个回复)
沙发
ryowu [专家分:6470] 发布于 2005-09-19 10:24:00
private void button1_Click(object sender, System.EventArgs e)
{
if(textBox1.Focused)
{
textBox1.Text = "1";
}
if(textBox2.Focused)
{
textBox2.Text = "1";
}
}
板凳
xiaojiezi [专家分:10] 发布于 2005-09-24 10:45:00
好像用VB.NET中的一个控件也可以的
3 楼
dchlmz [专家分:20] 发布于 2006-02-09 12:17:00
好象在2005中用不了focused,当点按钮时,焦点到按钮上了
4 楼
goodsirliu [专家分:180] 发布于 2006-02-09 21:31:00
Dim GotFocusTextboxName As String
Private Sub ChangeButtonText(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.LostFocus, TextBox1.LostFocus
GotFocusTextboxName = sender.name
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Select Case LCase(GotFocusTextboxName)
Case LCase("Textbox1")
Button1.Text = "1"
Case LCase("Textbox2")
Button1.Text = "1"
End Select
End Sub
Private Sub Button1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.LostFocus
GotFocusTextboxName = ""
End Sub
5 楼
xiaosen58 [专家分:0] 发布于 2006-02-22 17:41:00
你在北京工作吗?
可以加你MSN吗
我来回复