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

良朋 2003-12-02 10:04:51
如何让TEXTBOX或COMBOBOX 的ENABLED=FALSE 时不变暗?
即forecolor=colors.black
...全文
338 11 打赏 收藏 转发到动态 举报
写回复
用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
【更新至2025年】2001-2025年上市公司数字化转型年报词频统计(吴非、赵宸宇、甄红线)(300+年报词频统计) 1、间:2001-2025年 2、来源:上市公司年报 3、参考文献:企业数字化转型与资本市场表现——来自股票流动性的经验证据(吴非) 数字化转型如何影响企业全要素生产率(赵宸宇) 知识产权行政保护与企业数字化转型(甄红线) 4、方法说明:(1)参考吴非老师的做法,对人工智能技术、大数据技术、云计算技术、区块链技术、数字技术运用五个维度76个数字化相关词频进行统计 (2)参考赵宸宇老师的做法,对数字技术应用、互联网商业模式、智能制造、现代信息系统四个维度99个数字化相关词频进行统计 (3)参考甄红线老师的做法,对技术分类、组织赋能、数字化应用等类别下139个数字化相关词频进行统计 5、指标:年份、股票代码、公司简称、行业名称、行业代码、全文-文本总长度、仅中英文-文本总长度、人工智能技术-吴、大数据技术-吴、云计算技术-吴、区块链技术-吴、数字技术运用-吴、数字技术应用-赵、互联网商业模式-赵、智能制造-赵、现代信息系统-赵、技术分类-人工智能技术-甄、技术分类-区块链技术-甄、技术分类-云计算技术-甄、技术分类-大数据技术-甄、组织赋能-人工智能技术-甄、组织赋能-云计算技术-甄、组织赋能-大数据技术-甄、组织赋能-广义数字技术-甄、数字化应用-技术创新-甄、数字化应用-流程创新-甄、数字化应用-业务创新-甄、人工智能、商业智能、图像理解、投资决策辅助系统、智能数据分析、智能机器人、机器学习、深度学习、语义搜索、生物识别技术、人脸识别、语音识别、身份验证、自动驾驶、自然语言处理、大数据、数据挖掘、文本挖掘、数据可视化、异构数据、征信、增强现实、混合现实、虚拟现实、云计算、流计算、图计算、内存计算、多方安全计算、类脑计算、绿色计算、认知计算等300+词频

16,718

社区成员

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

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