如何让TEXTBOX或COMBOBOX 的ENABLED=FALSE 时不变暗?

良朋 2003-12-02 10:04:51
如何让TEXTBOX或COMBOBOX 的ENABLED=FALSE 时不变暗?
即forecolor=colors.black
...全文
269 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
rock1981 2003-12-08
  • 打赏
  • 举报
回复
其实 isage2002(isage) 方法蛮好的!
要重写TextBox 只要继承TextBox重写它的方法事件就是了!
brightheroes 2003-12-08
  • 打赏
  • 举报
回复
everything is done!汗死

brightheroes 2003-12-08
  • 打赏
  • 举报
回复
不用这么麻烦

在你的窗体的构造函数添加
{
InitializeComponent();
...
yourControl.BackColor = Color.Red;
}
everything is down!
rock29 2003-12-08
  • 打赏
  • 举报
回复
呵呵,你看得懂吗?
Public Class FlatTextBox

Inherits TextBox

Private mblnHighlight As Boolean = True
Private mclrHighlight As Color = SystemColors.Highlight
Private mclrBorder As Color = SystemColors.ControlDark

Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
MyBase.OnMouseEnter(e)
If mblnHighlight Then Invalidate()
End Sub

Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
MyBase.OnMouseLeave(e)
If mblnHighlight Then Invalidate()
End Sub

Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
MyBase.OnLostFocus(e)
If mblnHighlight Then Invalidate()
End Sub

Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
MyBase.OnGotFocus(e)
If mblnHighlight Then Invalidate()
End Sub

Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
If m.Msg <> Win32API.WM_PAINT Then Return
Dim wrec As Win32API.RECT
Win32API.GetWindowRect(Handle, wrec)
Dim recF As New RectangleF(0.0F, 0.0F, wrec.Right - wrec.Left, wrec.Bottom - wrec.Top)
Dim hDc As IntPtr = Win32API.GetWindowDC(Handle)
With Graphics.FromHdc(hDc)
Dim pen As Pen
Dim blnHighlight As Boolean = Not DesignMode AndAlso mblnHighlight AndAlso (Focused OrElse ClientRectangle.Contains(PointToClient(MousePosition)))
If Me.ReadOnly OrElse Not Enabled Then
.FillRectangle(SystemBrushes.Window, recF)
If Text <> String.Empty Then
Dim sf As New StringFormat
If Not Multiline AndAlso AutoSize Then sf.LineAlignment = StringAlignment.Center
Select Case TextAlign
Case HorizontalAlignment.Center
sf.Alignment = StringAlignment.Center
Case HorizontalAlignment.Right
sf.Alignment = StringAlignment.Far
End Select
Dim strText As String
If Multiline OrElse PasswordChar = Char.MinValue Then
strText = Text
Else
strText = New String(PasswordChar, Text.Length)
End If
If Me.ReadOnly AndAlso Enabled Then
Dim brush As New SolidBrush(ForeColor)
.DrawString(strText, Font, brush, recF, sf)
brush.Dispose()
If blnHighlight Then
pen = New Pen(mclrHighlight)
Else
pen = New Pen(mclrBorder)
End If
Else
.DrawString(strText, Font, SystemBrushes.ControlDark, recF, sf)
pen = New Pen(mclrBorder)
End If
sf.Dispose()
Else
pen = New Pen(mclrBorder)
End If
Else
pen = New Pen(SystemBrushes.Window)
.DrawRectangle(pen, 1.0F, 1.0F, recF.Width - 3.0F, recF.Height - 3.0F)
pen.Dispose()
If blnHighlight Then
pen = New Pen(mclrHighlight)
Else
pen = New Pen(mclrBorder)
End If
End If
.DrawRectangle(pen, 0.0F, 0.0F, recF.Width - 1.0F, recF.Height - 1.0F)
pen.Dispose()
.Dispose()
End With
Win32API.ReleaseDC(Handle, hDc)
End Sub

<DefaultValue(True), Category("Behavior"), Description("Indicates whether the control will have its border highlighted " & _
"when it receives focus or the mouse pointer enters its client rectangle. The default value is True.")> _
Public Property HighlightBorder() As Boolean
Get
Return mblnHighlight
End Get
Set(ByVal Value As Boolean)
If Value = mblnHighlight Then Return
mblnHighlight = Value
If Not DesignMode Then Invalidate()
End Set
End Property

<Category("Appearance"), Description("The color of the control's border when it receives focus or the mouse pointer enters its client rectangle.")> _
Public Property HighlightColor() As Color
Get
Return mclrHighlight
End Get
Set(ByVal Value As Color)
If Value.Equals(mclrHighlight) Then Return
mclrHighlight = Value
If Not DesignMode AndAlso mblnHighlight Then Invalidate()
End Set
End Property

<EditorBrowsable(EditorBrowsableState.Never)> _
Public Function ShouldSerializeHighlightColor() As Boolean
Return Not mclrHighlight.Equals(SystemColors.Highlight)
End Function

<Category("Appearance"), Description("The color of the control's border.")> _
Public Property BorderColor() As Color
Get
Return mclrBorder
End Get
Set(ByVal Value As Color)
If Value.Equals(mclrBorder) Then Return
mclrBorder = Value
Invalidate()
End Set
End Property

<EditorBrowsable(EditorBrowsableState.Never)> _
Public Function ShouldSerializeBorderColor() As Boolean
Return Not mclrBorder.Equals(SystemColors.ControlDark)
End Function

<Browsable(False)> _
Public Shadows ReadOnly Property BorderStyle() As BorderStyle
Get
Return MyBase.BorderStyle
End Get
End Property

End Class
良朋 2003-12-07
  • 打赏
  • 举报
回复
二楼的方法我试过,好象不行。
rock29(rock) 如何重写textbox,你有没试过?
cnicq 2003-12-03
  • 打赏
  • 举报
回复
up
rock29 2003-12-03
  • 打赏
  • 举报
回复
不行,要重写textbox
szch 2003-12-03
  • 打赏
  • 举报
回复
背景色设置一下就行了。
qiaoba 2003-12-03
  • 打赏
  • 举报
回复
用Readonly=false
poni 2003-12-03
  • 打赏
  • 举报
回复
设置backcolor属性
isage2002 2003-12-02
  • 打赏
  • 举报
回复
我为了保持美观,一般将编辑控件放到一个控件容器里,然后将控件容器的ENABLED=FALSE

16,721

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧