BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
public UserControl() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); this.label1.Hide(); this.label2.Hide(); this.label3.Hide(); this.panel1.Paint += new PaintEventHandler(panel1_Paint); } private void panel1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawString(this.label1.Text, this.label1.Font, Brushes.Black, this.label1.Location.X, this.label1.Location.Y); e.Graphics.DrawString(this.label2.Text, this.label2.Font, Brushes.Black, this.label2.Location.X, this.label2.Location.Y); e.Graphics.DrawString(this.label3.Text, this.label3.Font, Brushes.Black, this.label3.Location.X, this.label3.Location.Y); }
//in OnInitialize
MakeUnBuffered(this.panel1);
//method
private void MakeUnBuffered(Control c)
{
System.Reflection.MethodInfo mInfo = typeof(Control).GetMethod("SetStyle",
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.InvokeMethod |
System.Reflection.BindingFlags.NonPublic);
if(mInfo != null)
{
mInfo.Invoke(c, new object[]{ControlStyles.DoubleBuffer, false});
}
if(c.Controls.Count > 0)
{
foreach (Control c1 in c.Controls)
{
c1.CausesValidation = false;
MakeUnBuffered(c1);//recursive call
}
}
}
You can see a sample use of this technique in the grid\samples\databound\repeatercontrol sample.
private void Form1_Load(object sender, System.EventArgs e) { //UserControl uc = new UserControl(); //Label l = new Label(); Panel uc = new Panel(); Label l = new CustomLabelWithBackColor(); //MakeUnBuffered(l); l.Text = "Text"; l.BackColor = Color.Red; l.Bounds = new Rectangle(5, 5, 50, 50);//DockStyle.Fill; uc.Controls.Add(l); this.gridControl1[2,2].CellType = "Control"; this.gridControl1[2,2].Control = uc; this.gridControl1.RowHeights[2] = 50; this.gridControl1.ColWidths[2] = 100; } public class CustomLabelWithBackColor : Label { protected override void OnPaint(PaintEventArgs e) { // either do manually call OnPaintBackground this.OnPaintBackground(e); // or simply draw background here // using (SolidBrush brush = new SolidBrush(BackColor)) // { // e.Graphics.FillRectangle(brush, e.ClipRectangle); // } base.OnPaint (e); } }