ir_programmer
پنج شنبه 08 آذر 1386, 08:41 صبح
در ادامه پست :
http://barnamenevis.org/forum/showthread.php?t=85602
سوال:
چگونه یک Text Box یا کنترل دیگری را Read Only کنید ولی بصورت خاکستری رنگ و ناخوانا نشود ؟
راه حل:
می بایست کلاس کنترل خود را Customize کنید.
بطور مثال در مورد Text Box:
Public Class VisualTextbox
Inherits TextBox
Public Sub New()
' Initialise the class
MyBase.New()
End Sub
Public Shadows Property Enabled() As Boolean
Get
Return MyBase.Enabled
End Get
Set(ByVal Value As Boolean)
SetDrawingStyle(Not Value)
' Set the underlying value
MyBase.Enabled = Value
End Set
End Property
Private Sub SetDrawingStyle(ByVal customPaint As Boolean)
' Switch draw styles if disabled
Me.SetStyle(ControlStyles.UserPaint, customPaint)
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
' Draw the bg in
e.Graphics.FillRectangle(New SolidBrush(Color.Gold), Me.ClientRectangle)
' Draw the appropriate text in using the fore color
e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), -1, 1)
End Sub
Protected Overrides Sub OnEnabledChanged(ByVal e As System.EventArgs)
MyBase.OnEnabledChanged(e)
SetDrawingStyle(Not Me.Enabled)
Me.Refresh()
End Sub
End Class
مثال هم Attach شده.
http://barnamenevis.org/forum/showthread.php?t=85602
سوال:
چگونه یک Text Box یا کنترل دیگری را Read Only کنید ولی بصورت خاکستری رنگ و ناخوانا نشود ؟
راه حل:
می بایست کلاس کنترل خود را Customize کنید.
بطور مثال در مورد Text Box:
Public Class VisualTextbox
Inherits TextBox
Public Sub New()
' Initialise the class
MyBase.New()
End Sub
Public Shadows Property Enabled() As Boolean
Get
Return MyBase.Enabled
End Get
Set(ByVal Value As Boolean)
SetDrawingStyle(Not Value)
' Set the underlying value
MyBase.Enabled = Value
End Set
End Property
Private Sub SetDrawingStyle(ByVal customPaint As Boolean)
' Switch draw styles if disabled
Me.SetStyle(ControlStyles.UserPaint, customPaint)
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
' Draw the bg in
e.Graphics.FillRectangle(New SolidBrush(Color.Gold), Me.ClientRectangle)
' Draw the appropriate text in using the fore color
e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), -1, 1)
End Sub
Protected Overrides Sub OnEnabledChanged(ByVal e As System.EventArgs)
MyBase.OnEnabledChanged(e)
SetDrawingStyle(Not Me.Enabled)
Me.Refresh()
End Sub
End Class
مثال هم Attach شده.