Peter, I'm not unwilling to "put the correct level of effort" into my
question, I simply don't know what should I put as a concise-but-
complete code example in this case!
The word "complete" should be just as informative to you as "concise".
Both matter.
Here are some links you may find helpful:
http://www.yoda.arachsys.com/csharp/complete.html
http://www.yoda.arachsys.com/csharp/incomplete.html
http://sscce.org/ (some Java-centric stuff, but mostly applicable to any
programming questions)
That said, I went ahead and wrote a short sample that demonstrates the
specific ideas I've described. As an added bonus, as an actual
concise-but-complete code example, it should help you understand what is
meant by that phrase.
![Smile :) :)](/styles/default/custom/smilies/smile.gif)
You'll note in that example that the only
sub-classes I had to create are of System.Windows.Forms.Form and
System.Windows.Forms.Control. No need to sub-class Panel (which is used
as a scrollable container in my example) nor UserControl (which is
completely unneeded).
Pete
using System;
using System.Windows.Forms;
using System.Drawing;
namespace TestDoubleBufferedScrolling_OneFile
{
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public class Form1 : Form
{
public Form1()
{
InitializeComponent();
tboxWidth.Text = customControl11.Width.ToString();
tboxHeight.Text = customControl11.Height.ToString();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox check = (CheckBox)sender;
customControl11.DoubleBuffered = check.Checked;
customControl11.Invalidate();
}
private void tboxWidth_TextChanged(object sender, EventArgs e)
{
int dxWidth;
if (int.TryParse(tboxWidth.Text, out dxWidth))
{
customControl11.Width = dxWidth;
}
}
private void tboxHeight_TextChanged(object sender, EventArgs e)
{
int dxHeight;
if (int.TryParse(tboxHeight.Text, out dxHeight))
{
customControl11.Height = dxHeight;
}
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.tboxWidth = new System.Windows.Forms.TextBox();
this.tboxHeight = new System.Windows.Forms.TextBox();
this.customControl11 = new
TestDoubleBufferedScrolling_OneFile.CustomControl1();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Anchor =
((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.AutoScroll = true;
this.panel1.Controls.Add(this.customControl11);
this.panel1.Location = new System.Drawing.Point(13, 37);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(528, 335);
this.panel1.TabIndex = 0;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(13, 13);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(100, 17);
this.checkBox1.TabIndex = 1;
this.checkBox1.Text = "DoubleBuffered";
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new
System.EventHandler(this.checkBox1_CheckedChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(127, 14);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(38, 13);
this.label1.TabIndex = 2;
this.label1.Text = "Width:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(274, 14);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(41, 13);
this.label2.TabIndex = 3;
this.label2.Text = "Height:";
//
// tboxWidth
//
this.tboxWidth.Location = new System.Drawing.Point(168, 11);
this.tboxWidth.Name = "tboxWidth";
this.tboxWidth.Size = new System.Drawing.Size(100, 20);
this.tboxWidth.TabIndex = 4;
this.tboxWidth.TextChanged += new
System.EventHandler(this.tboxWidth_TextChanged);
//
// tboxHeight
//
this.tboxHeight.Location = new System.Drawing.Point(321, 11);
this.tboxHeight.Name = "tboxHeight";
this.tboxHeight.Size = new System.Drawing.Size(100, 20);
this.tboxHeight.TabIndex = 5;
this.tboxHeight.TextChanged += new
System.EventHandler(this.tboxHeight_TextChanged);
//
// customControl11
//
this.customControl11.DoubleBuffered = false;
this.customControl11.Location = new System.Drawing.Point(4, 3);
this.customControl11.Name = "customControl11";
this.customControl11.Size = new System.Drawing.Size(521, 329);
this.customControl11.TabIndex = 0;
this.customControl11.Text = "customControl11";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(553, 384);
this.Controls.Add(this.tboxHeight);
this.Controls.Add(this.tboxWidth);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Panel panel1;
private CustomControl1 customControl11;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox tboxWidth;
private System.Windows.Forms.TextBox tboxHeight;
}
public class CustomControl1 : Control
{
public CustomControl1()
{
InitializeComponent();
}
public new bool DoubleBuffered
{
get { return base.DoubleBuffered; }
set { base.DoubleBuffered = value; }
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
string strText = "Test Pattern";
SizeF sizeText = pe.Graphics.MeasureString(strText, Font);
using (Brush brush = new SolidBrush(ForeColor))
{
PointF ptDraw = new PointF();
while (ptDraw.Y < Height)
{
while (ptDraw.X < Width)
{
pe.Graphics.DrawString(strText, Font, brush,
ptDraw);
ptDraw.X += sizeText.Width;
}
ptDraw.X = 0;
ptDraw.Y += sizeText.Height;
}
}
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}