那就readonly吧,怎么好像回过一个这样的贴子了?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Necsoft.Medical.Lacs.Forms
{
public partial class myTextBox : TextBox
{
private TextBox ptxt = null;
private bool pbmyEnabled = true;
public myTextBox()
: base()
{
InitializeComponent();
}
public new bool Enabled
{
get
{
return pbmyEnabled;
}
set
{
pbmyEnabled = value;
base.Enabled = value;
if (pbmyEnabled)
{
if (ptxt != null && this.Controls.Contains(ptxt))
{
Text = ptxt.Text;
this.Controls.Remove(ptxt);
}
//BackColor = SystemColors.Window;
}
else
{
if (ptxt == null)
{
ptxt = new TextBox();
ptxt.AutoSize = false;
ptxt.Enabled = true;
ptxt.Location = new Point(-2, -2);
ptxt.Size = this.Size;
ptxt.BackColor = Color.Green;
ptxt.ForeColor = Color.Red;
}
ptxt.Font = this.Font;
ptxt.Text = Text;
Text = String.Empty;
Controls.Add(ptxt);
//BackColor = Color.Black;
}
}
}
protected override void OnPaint(PaintEventArgs e)
{
if (Enabled)
{
base.OnPaint(e);
}
}
}
}