首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

让TextBox控件显示为一条横线,该如何处理

2012-02-11 
让TextBox控件显示为一条横线1、把textbox控件 BorderStyleFixedSingle 然后在下面加lable显示为横线,这个

让TextBox控件显示为一条横线
1、把textbox控件 BorderStyle=FixedSingle 然后在下面加lable显示为横线,这个方法简单,但是麻烦呀。。

2、能不能重写textbox,如何重写(分不够还加。。。)

[解决办法]

VB.NET code
Public Class MyTextbox    Inherits System.Windows.Forms.TextBox    Protected Overrides Sub WndProc(ByRef m As Message)        MyBase.WndProc(m)        If m.Msg = &HF Then            Using g As Graphics = Graphics.FromHwnd(Me.Handle)                g.DrawLine(Pens.Blue, 0, Me.ClientRectangle.Height - 1, Me.Width, Me.ClientRectangle.Height - 1)            End Using        End If    End SubEnd Class
[解决办法]
VB.NET code
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint        For Each Tb As TextBox In Me.Controls            If TypeOf (Tb) Is TextBox Then                Tb.BorderStyle = BorderStyle.None  去掉边框                e.Graphics.DrawLine(Pens.Black, New Point(Tb.Left, Tb.Top + Tb.Height + 2), New Point(Tb.Left + Tb.Width, Tb.Top + Tb.Height + 2))            End If        Next    End Sub
[解决办法]
探讨

VB.NET code
Public Class MyTextbox
Inherits System.Windows.Forms.TextBox

Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
If m.Msg = &HF Then
……

热点排行