如何使TextBox表现出来...... [英] How to Make a TextBox Behave...

查看:61
本文介绍了如何使TextBox表现出来......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使TextBox的行为与IE中的地址栏相似?那是......


如果焦点不在tb上,如果点击tb或

标签到tb,请选择所有文本。再次单击取消选择文本并将

插入点设置为单击的位置。


我已经尝试了从TextBox继承的几个选项,但没有一个工作相当

吧。


非常感谢,

Gene H.

How do I make a TextBox behave like the address bar in IE? That is...

If focus is not on the tb, select all text if clicking on the tb or
tabbing into the tb. Clicking again deselects the text and sets the
insertion point to where clicked.

I''ve tried several options inheriting from TextBox but none work quite
right.

Thanks Much,
Gene H.

推荐答案

你可以这样做:


私有bJustGotFocus为boolean''(类级布尔变量)


private sub TextBox1_GotFocus(byval sender as object,_

byval e as System.EventArgs)Handles TextBox1.GotFocus

bJustGotFocus = True

end sub


private sub TextBox1_LostFocus(byval sender as object,_

byval e as System.EventArgs)Handles TextBox1.LostFocus

bJustGotFocus = False

end sub


private sub TextBox1_MouseDown(byval sender as object,_

byval e as System.Windows.Forms.MouseEventArgs )_

处理TextBox1.MouseDown

如果bJustGotFocus那么

TextBox1.Select(0,TextBox1.TextLength)

bJustGotFocus = false

结束如果

end sub


应该像地址栏文本框一样工作..

希望这会有所帮助..

imran。


" Gene Hubert" < GW ****** @ hotmail.com>在留言中写道

news:7e ************************** @ posting.google.c om ...
you could do something like this:

Private bJustGotFocus as boolean ''(class level boolean variable)

private sub TextBox1_GotFocus(byval sender as object, _
byval e as System.EventArgs) Handles TextBox1.GotFocus
bJustGotFocus = True
end sub

private sub TextBox1_LostFocus(byval sender as object, _
byval e as System.EventArgs) Handles TextBox1.LostFocus
bJustGotFocus = False
end sub

private sub TextBox1_MouseDown(byval sender as object, _
byval e as System.Windows.Forms.MouseEventArgs) _
Handles TextBox1.MouseDown
if bJustGotFocus then
TextBox1.Select(0, TextBox1.TextLength)
bJustGotFocus = false
end if
end sub

should work like the address bar textbox..
hope this helps..
imran.

"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om...
如何使TextBox的行为与IE中的地址栏相似?那就是......

如果焦点不在tb上,如果点击tb或
标签进入tb,请选择所有文字。再次单击取消选择文本并将
插入点设置为单击的位置。

我已尝试从TextBox继承的几个选项,但没有一个正常工作。

非常感谢,
Gene H。
How do I make a TextBox behave like the address bar in IE? That is...

If focus is not on the tb, select all text if clicking on the tb or
tabbing into the tb. Clicking again deselects the text and sets the
insertion point to where clicked.

I''ve tried several options inheriting from TextBox but none work quite
right.

Thanks Much,
Gene H.



我认为这是你的想法,但它不起作用。它处理

的情况下点击文本框但没有处理选项卡到文本框中的
。我之前和之后尝试了几种不同的变化

我的原始帖子但没有一种工作正常。


这是一个常见的UI元素,我我想在找到这个小组后我会找到答案

,但我不认为它在那里。


看起来很简单。还有其他人想要参加吗?


Gene H.


============= =================

选项严格开启

选项明确开启


公共类BaseTextBox

继承System.Windows.Forms.TextBox


私有bJustGotFocus为boolean''(类级布尔变量)


private sub TextBox1_GotFocus(byval sender as object,byval e as

System.EventArgs)Handles MyBase.GotFocus

bJustGotFocus = True

end sub


private sub TextBox1_LostFocus(byval sender as object,byval e as

System.EventArgs)处理MyBase.LostFocus

bJustGotFocus = False

end sub


private sub TextBox1_MouseDown(byval发送者作为对象,byval e as

系统。 Windows.Forms.MouseEventArgs)处理MyBase.MouseDown

如果bJustGotFocus那么

me.Select(0,me.TextLength)

bJustGotFocus = false

结束如果

结束子

结束班

==================== ==============

" Imran Koradia" <无**** @ microsoft.com>在消息新闻中写道:< eZ ************** @ tk2msftngp13.phx.gbl> ...
I think this is what you had in mind but it does not work. It handles
the case of clicking into the textbox but does not handle tabbing into
the textbox. I''ve tried several variations of this before and after
my original post but none worked quite right.

This is such a common UI element that I thought I''d find the answer
right away after searching this group but I don''t think it is there.

It seems simple enough. Anyone else want to have a run at it?

Gene H.

==============================
Option Strict On
Option Explicit On

Public Class BaseTextBox
Inherits System.Windows.Forms.TextBox

Private bJustGotFocus as boolean ''(class level boolean variable)

private sub TextBox1_GotFocus(byval sender as object, byval e as
System.EventArgs) Handles MyBase.GotFocus
bJustGotFocus = True
end sub

private sub TextBox1_LostFocus(byval sender as object, byval e as
System.EventArgs) Handles MyBase.LostFocus
bJustGotFocus = False
end sub

private sub TextBox1_MouseDown(byval sender as object, byval e as
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
if bJustGotFocus then
me.Select(0, me.TextLength)
bJustGotFocus = false
end if
end sub
End Class
==================================
"Imran Koradia" <no****@microsoft.com> wrote in message news:<eZ**************@tk2msftngp13.phx.gbl>...
你可以这样做:
私有bJustGotFocus为boolean''(类级布尔变量)
私有子TextBox1_GotFocus(byval发送者作为对象,_
byval e as System.EventArgs)处理TextBox1.GotFocus
bJustGotFocus = True
结束sub

私有子TextBox1_LostFocus(byval发送者作为对象,_
byval e as System.EventArgs)处理TextBox1.LostFocus
bJustGotFocus = False
结束sub
私有子TextBox1_MouseDown(byval发送者作为对象,_
byval e as System.Windows.Forms.MouseEventArgs)_
处理TextBox1。 MouseDown
如果bJustGotFocus那么
TextBox1.Select(0,TextBox1.TextLength)
bJustGotFocus = false
结束如果
结束子

应该像地址栏文本框一样工作..
希望这样帮助..
imran。

Gene Hubert < GW ****** @ hotmail.com>在消息中写道
新闻:7e ************************** @ posting.google.c om ...
you could do something like this:

Private bJustGotFocus as boolean ''(class level boolean variable)

private sub TextBox1_GotFocus(byval sender as object, _
byval e as System.EventArgs) Handles TextBox1.GotFocus
bJustGotFocus = True
end sub

private sub TextBox1_LostFocus(byval sender as object, _
byval e as System.EventArgs) Handles TextBox1.LostFocus
bJustGotFocus = False
end sub

private sub TextBox1_MouseDown(byval sender as object, _
byval e as System.Windows.Forms.MouseEventArgs) _
Handles TextBox1.MouseDown
if bJustGotFocus then
TextBox1.Select(0, TextBox1.TextLength)
bJustGotFocus = false
end if
end sub

should work like the address bar textbox..
hope this helps..
imran.

"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om...
如何使TextBox的行为与IE中的地址栏相似?那就是......

如果焦点不在tb上,如果点击tb或
标签进入tb,请选择所有文字。再次单击取消选择文本并将
插入点设置为单击的位置。

我已尝试从TextBox继承的几个选项,但没有一个正常工作。

非常感谢,
Gene H。
How do I make a TextBox behave like the address bar in IE? That is...

If focus is not on the tb, select all text if clicking on the tb or
tabbing into the tb. Clicking again deselects the text and sets the
insertion point to where clicked.

I''ve tried several options inheriting from TextBox but none work quite
right.

Thanks Much,
Gene H.



嗯......我明白你的意思了。如果您第一次点击,它将选择

全文。第二次单击时,它只是将光标设置为

位置。之后,每次使用tab键选中该文本框时,

它只显示光标而不选择整个文本。所以 - 让我们再次尝试这个
,这次是2布尔:)


私有bHasFocus作为布尔''类级布尔变量

Private bJustGotFocus As Boolean''class level boolean variable

Private Sub TextBox1_GotFocus(ByVal sender As Object,_

ByVal e As System.EventArgs)Handles TextBox1.GotFocus

TextBox1.Select(0,TextBox1.TextLength)

bHasFocus = True

结束子


Private Sub TextBox1_LostFocus(ByVal sender As Object,_

ByVal e As System.EventArgs)处理TextBox1.LostFocus

bHasFocus = False

bJustGotFocus =错误

结束子


私有子TextBox1_MouseDown(ByVal发件人作为对象,_

ByVal e As System.Windows.Forms。 MouseEventArgs)_

处理TextBox1.MouseDown

如果不是bHasFocus或不是bJustGotFocus那么

TextBox1.Select(0,TextBox1.TextLength)

bHasFocus = Tru e $>
bJustGotFocus = True

结束如果

End Sub


这适用于我的机器 - 或者至少我是这么认为的:)尝试一下吧让我知道

知道它是否有帮助..

imran。


Gene Hubert < GW ****** @ hotmail.com>在留言中写道

news:7e ************************** @ posting.google.c om ...
hmmm..I see your point. If you click the first time, it will select the
whole text. the second time you click, it just sets the cursor to that
position. after that, everytime you tab into that textbox using the tab key,
it just shows the cursor and does not select the entire text. so - lets try
this again and this time with 2 booleans :)

Private bHasFocus As Boolean ''class level boolean variable
Private bJustGotFocus As Boolean ''class level boolean variable
Private Sub TextBox1_GotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TextBox1.GotFocus
TextBox1.Select(0, TextBox1.TextLength)
bHasFocus = True
End Sub

Private Sub TextBox1_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TextBox1.LostFocus
bHasFocus = False
bJustGotFocus = False
End Sub

Private Sub TextBox1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles TextBox1.MouseDown
If Not bHasFocus Or Not bJustGotFocus Then
TextBox1.Select(0, TextBox1.TextLength)
bHasFocus = True
bJustGotFocus = True
End If
End Sub

this works on my machine - or atleast i think so :) give it a try and let me
know if it helps..
imran.

"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om...
我认为这是你的想法,但它不起作用。它处理单击文本框的情况,但不处理选项卡进入文本框。我之前和之后尝试了几种不同的原因,但我的原始帖子都没有用。

这是一个常见的UI元素,我认为我会找到答案
在搜索了这个小组之后马上就知道了。

这看起来很简单。还有其他人想要参加吗?

Gene H.

===================== =========
Option Strict On
Option Explicit On

公共类BaseTextBox
继承System.Windows.Forms.TextBox

私有bJustGotFocus为boolean''(类级布尔变量)
私有子TextBox1_GotFocus(byval发送者作为对象,byval e as
System.EventArgs)处理MyBase.GotFocus
bJustGotFocus = True
结束sub
私有子TextBox1_LostFocus(byval发送者作为对象,byval e as
System.EventArgs)处理MyBase.LostFocus
bJustGotFocus = False
结束sub

私有子TextBox1_MouseDown(byval发送者作为对象,byval e as
System.Windows.Forms.MouseEventArgs)处理MyBase.MouseDown
如果bJustGotFocus然后
me.Select(0,me.TextLength)
bJustGotFocus = false
结束如果
结束子
结束类
======== ======================== ==

" Imran Koradia" <无**** @ microsoft.com>在消息中写道
I think this is what you had in mind but it does not work. It handles
the case of clicking into the textbox but does not handle tabbing into
the textbox. I''ve tried several variations of this before and after
my original post but none worked quite right.

This is such a common UI element that I thought I''d find the answer
right away after searching this group but I don''t think it is there.

It seems simple enough. Anyone else want to have a run at it?

Gene H.

==============================
Option Strict On
Option Explicit On

Public Class BaseTextBox
Inherits System.Windows.Forms.TextBox

Private bJustGotFocus as boolean ''(class level boolean variable)

private sub TextBox1_GotFocus(byval sender as object, byval e as
System.EventArgs) Handles MyBase.GotFocus
bJustGotFocus = True
end sub

private sub TextBox1_LostFocus(byval sender as object, byval e as
System.EventArgs) Handles MyBase.LostFocus
bJustGotFocus = False
end sub

private sub TextBox1_MouseDown(byval sender as object, byval e as
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
if bJustGotFocus then
me.Select(0, me.TextLength)
bJustGotFocus = false
end if
end sub
End Class
==================================
"Imran Koradia" <no****@microsoft.com> wrote in message



news:< eZ ************** @ tk2msftngp13.phx.gbl> ...


news:<eZ**************@tk2msftngp13.phx.gbl>...

你可以这样做:

私人bJustGotFocus为布尔''(类级布尔变量)
私有子TextBox1_GotFocus(byval发送者为对象,_
byval e as System.EventArgs)处理TextBox1.GotFocus
bJustGotFocus = True
结束子
私有子TextBox1_LostFocus(byval sender as object, _
byval e as System.EventArgs)处理TextBox1.LostFocus
bJustGotFocus = False
结束sub
私有子TextBox1_MouseDown(byval sender as object,_
byval e as System.Windows.Forms.MouseEventArgs)_
处理TextBox1.MouseDown
如果bJustGotFocus则
TextBox1.Select(0,TextBox1.TextLength)
bJustGotFocus = false <结束如果
结束了

笑你的工作方式就像地址栏文本框一样..
希望这会有所帮助..
imran。

Gene Hubert < GW ****** @ hotmail.com>在消息中写道
新闻:7e ************************** @ posting.google.c om ...
you could do something like this:

Private bJustGotFocus as boolean ''(class level boolean variable)

private sub TextBox1_GotFocus(byval sender as object, _
byval e as System.EventArgs) Handles TextBox1.GotFocus
bJustGotFocus = True
end sub

private sub TextBox1_LostFocus(byval sender as object, _
byval e as System.EventArgs) Handles TextBox1.LostFocus
bJustGotFocus = False
end sub

private sub TextBox1_MouseDown(byval sender as object, _
byval e as System.Windows.Forms.MouseEventArgs) _
Handles TextBox1.MouseDown
if bJustGotFocus then
TextBox1.Select(0, TextBox1.TextLength)
bJustGotFocus = false
end if
end sub

should work like the address bar textbox..
hope this helps..
imran.

"Gene Hubert" <gw******@hotmail.com> wrote in message
news:7e**************************@posting.google.c om...
如何使TextBox的行为与IE中的地址栏相似?那就是......

如果焦点不在tb上,如果点击tb或
标签进入tb,请选择所有文字。再次单击取消选择文本并将
插入点设置为单击的位置。

我已尝试从TextBox继承的几个选项,但没有一个正常工作。

非常感谢,
Gene H。
How do I make a TextBox behave like the address bar in IE? That is...

If focus is not on the tb, select all text if clicking on the tb or
tabbing into the tb. Clicking again deselects the text and sets the
insertion point to where clicked.

I''ve tried several options inheriting from TextBox but none work quite
right.

Thanks Much,
Gene H.



这篇关于如何使TextBox表现出来......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆