using System; using System.Windows.Forms; using System.Drawing; namespace GForms { class GForm : Control { // This is a GControl host, meant to be put inside a form. // It's not actually a form by itself. All it contains is // a generic GControl object that holds other GControls. private GControl mainControl = new GControl(); public GForm() { this.Dock = DockStyle.Fill; this.DoubleBuffered = true; this.SetStyle(ControlStyles.ContainerControl, false); // no controls can be added this.MainControl.Changed += (GControl sender) => this.Invalidate(); } protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; // draw the main control this.MainControl.DrawBackground(g, this.ClientRectangle); this.MainControl.Draw(g, this.ClientRectangle); // raise the base event base.OnPaint(e); } protected override void OnMouseDown(MouseEventArgs e) { this.MainControl.OnMouseDown(e.Location, e.Button); base.OnMouseDown(e); } protected override void OnMouseUp(MouseEventArgs e) { this.MainControl.OnMouseUp(e.Location, e.Button); base.OnMouseUp(e); } protected override void OnMouseMove(MouseEventArgs e) { this.MainControl.OnMouseMove(e.Location, e.Button); base.OnMouseMove(e); } public GControl MainControl { get { return mainControl; } } } }