如何使用文本框但有下划线和闪烁的光标? [英] how to use a textbox but having an underscore line and blinking cursor?
问题描述
我已经创建了 Windows 表单,我使用文本框控件进行输入,但我喜欢使用它没有边框和其他布局的文本框等.我只想使用下划线和闪烁的光标.
I've created Windows forms and I'm using the textbox control for input, but I like to use it without border and other layout for textbox etc. I just want to use a underscore line and blinking cursor.
我使用了 borderStyle(Fixed3D,None),backcolor=InactiveBorder 等.但我仍然确实得到了下划线...像这样-> _____________ 结果如下:这是下划线______________
I played with the borderStyle (Fixed3D, None), backcolor=InactiveBorder etc. But I still do net get the underline... like this-> _____________ result like this: This is underline______________
我认为 Backcolor=InactiveBorder 和 BorderStyle=None 可以使用,但是如何获得下划线和闪烁的光标?
I think Backcolor=InactiveBorder and BorderStyle=None is ok to use, but how to get the underline and blinking cursor?
要求:
- 闪烁光标和下划线.(默认情况下不闪烁,我只看到一条垂直线))
推荐答案
要为您的 textbox
创建下划线
,您可以这样做,
For creating a underline
for your textbox
you can do like this,
- 首先添加一个
panel
,其高度为文本框高度+下划线高度. - 现在将您的
textbox
添加到该panel
中,并将其dock
设置为TOP
. - 然后将文本框的
border
设置为none
. - 现在根据下划线的颜色需要设置
panel
的backcolor
.
- First add a
panel
which is in the height of text box's height + underline's height. - Now add your
textbox
inside of thatpanel
and set itsdock
toTOP
. - Then set the textbox's
border
tonone
. - Now set the
backcolor
of thepanel
, according to the color need of underline.
[ 概念:您只需将所有文本框的边框设置为无.然后在表单绘制事件中跟踪这些文本框并在其下方画一条线.]
[ Concept: You just need to set the border for all of your textboxes as none.then In forms paint event track those text boxes and draw a line under it. ]
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles Me.Paint
Using xPen As Pen = New Pen(Color.Blue)
' Here we are using LINQ to filter the controls.
' If you don't want it, you just check all the controls by using typeof
' inside the For Each loop.
For Each xTxtBox In Me.Controls.OfType(Of TextBox)()
e.Graphics.DrawLine(xPen,
xTxtBox.Location.X,
xTxtBox.Location.Y + xTxtBox.Height,
xTxtBox.Location.X + xTxtBox.Width,
xTxtBox.Location.Y + xTxtBox.Height)
Next
End Using
End Sub
这篇关于如何使用文本框但有下划线和闪烁的光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!