我用如下代码改变边框的颜色,但是当窗体被其它遮住后,再回到窗体时,边框颜色不见了????????Me.DrawWidth = 2
Line (Text1.Left, Text1.Top)-(Text1.Left + Text1.Width, Text1.Top + Text1.Height), &HDCC1AD, B
Line (Text1.Left, Text1.Top)-(Text1.Left + Text1.Width, Text1.Top + Text1.Height), &HDCC1AD, B
Private Declare Function DeleteObject Lib "gdi32 " (ByVal hObject As Long) As Long
Private Declare Function SetWindowRgn Lib "user32 " (ByVal hWnd As Long, ByVal hrgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function CreateRoundRectRgn Lib "gdi32 " (ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer, ByVal X3 As Integer, ByVal Y3 As Integer) As Long
Private Declare Function SelectObject Lib "gdi32 " (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32 " (ByVal crColor As Long) As Long
Private Declare Function CreatePen Lib "gdi32 " (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function RoundRect Lib "gdi32 " (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Const PS_SOLID = 0
Private Sub Form_Load()
Form1.ScaleMode = 3
Dim i As Long
Dim pen As Long
i = CreatePen(PS_SOLID, 1, RGB(234, 3, 45))
pen = SelectObject(Me.hdc, i)
Dim hrgn As Long
hrgn = CreateRoundRectRgn(2, 2, Text1.Width - 1, Text1.Height - 1, 10, 10)
SetWindowRgn Text1.hWnd, hrgn, True
DeleteObject hrgn
RoundRect Me.hdc, Text1.Left, Text1.Top, Text1.Left + Text1.Width, Text1.Height + Text1.Top, 10, 10
SelectObject Me.hdc, pen
DeleteObject i
End Sub
1、点击工程-》部件-》Microsoft Forms 2.0 Object Library 添加引用
2、在工具栏中选择TextBox(注意了,是下面的那个显示有“ab|”的TextBox)
3、把BorderSytle设置为:1
4、把BorderColor设置为:红色完成以上设置,就OK了
Private Sub Form_Load()
Text1.BorderStyle = 0
Shape1.BorderColor = vbRed
Shape1.Width = Text1.Width + 30
Shape1.Height = Text1.Height + 30
Shape1.Top = Text1.Top - 15
Shape1.Left = Text1.Left - 15
End Sub
2.Microsoft Forms 2.0 Object Library
加了Me.AutoRedraw = True后,左边框看不到线条。
如果用这个控件,那么TextBox前好像有个空格,怎么去掉?
1,先通过一个控件的hwnd,获取到她的rect
2,转换坐标
3,用API画一个框(类似5楼那样)
~~~~~~~~~~