PDA

View Full Version : Read Only کردن کنترلها بدون مات شدن



ir_programmer
پنج شنبه 08 آذر 1386, 07: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 شده.

UpgradeVB6Code
پنج شنبه 08 آذر 1386, 14:08 عصر
سلام
میشه راجع به کدت یه توضیح فارسی به صورت فارسی بذاری ! ( در سطح مقدماتی )

babak23
پنج شنبه 08 آذر 1386, 14:17 عصر
در مورد کنترل های دیگه هم چک کردی؟ میتونی یک مثال با Gruopbox , و رادیو باتم بزنی
من با این دو کنترل نتونستم کار کنم.و کنترل های دیگه را هم چک نکردم
با این روش به ازای هر نوع کنترلی باید یک کلاس بسازیم این زیاد خوشایند نیست!!!

morteza_261
پنج شنبه 08 آذر 1386, 14:23 عصر
با سلام
من که با نسخه 2005 کار میکنم فقط پس زمینه textbox که readonly هست رو به سفید تغییر میدم.

babak23
شنبه 10 آذر 1386, 08:21 صبح
این مورد به نظر حل نشده پس گفتگوی حل شده نمی تونه باشه و جای بحث داره !!!؟