این تبدیل شده ی کد مورد نظر است من این کد را در کجای سی شارپ باید استفاده کنم؟
publicclassVisualTextbox : TextBox
{
public VisualTextbox()
: base()
{
// Initialise the class
}
publicnewbool Enabled
{
get { returnbase.Enabled; }
set
{
SetDrawingStyle(!value);
// Set the underlying value
base.Enabled = value;
}
}
privatevoid SetDrawingStyle(bool customPaint)
{
// Switch draw styles if disabled
this.SetStyle(ControlStyles.UserPaint, customPaint);
}
protectedoverridevoid OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
// Draw the bg in
e.Graphics.FillRectangle(newSolidBrush(Color.Gold), this.ClientRectangle);
// Draw the appropriate text in using the fore color
e.Graphics.DrawString(this.Text, this.Font, newSolidBrush(this.ForeColor), -1, 1);
}
protectedoverridevoid OnEnabledChanged(System.EventArgs e)
{
base.OnEnabledChanged(e);
SetDrawingStyle(!this.Enabled);
this.Refresh();
}
}
در این کد رنگ تکست باکس عوض میشه و به صورت طلایی در مییاد یعنی در حقیقت موقعی که یک تکست باکس را غیر فعال میکنیم بجای اینکه به رنگ خاکستری در بیاد به رنگ طلایی در میاد.