I have an issue with C# richtextbox and Microsoft equation editor. My goal is to read, modify and save changes in rtf file.
I followed tutorial below:
C# Tutorial : How to insert Math Equation to RichTextBox | FoxLearn
I can read and modify equation in editor, however I can't update richtextbox after modification, modified value is not changed in richtboxtext.
Initial state
Modification
Update(F3) and exit in equation editor doesn't cause change in richtextbox.
However when I double click equation in editor there is changed value.
Here is my code:
using System;
using System.Windows.Forms;
namespace Panel.Views
{
public partial class Axis : Form
{
public Axis()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.SelectedRtf = Panel.Properties.Resources.Plot1_x_axis;
}
}
}
namespace Panel.Views
{
partial class Axis
{
/// <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.button1 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(723, 431);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(28, 36);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(770, 372);
this.richTextBox1.TabIndex = 1;
this.richTextBox1.Text = "";
//
// Axis
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(822, 478);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.button1);
this.Name = "Axis";
this.Text = "Axis";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.RichTextBox richTextBox1;
}
}
I would be appreciated for any help, hints or suggestions how to solve this issue.
Thank you in advance.
Related
For instance, if there is a push button, when the user press the button, the system should detect and record the time in dd-mm-yy. However, if the user press the button many time in 2 second, the system should only record the first time when the user press the button.
Assumption: you want to collect clicks but no more often than every 2 seconds. This simple form will do it.
Code:
namespace RecordClicks {
public partial class Form1 : Form {
private DateTime _recordedClick = DateTime.MinValue;
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
DateTime currentClickTime = DateTime.Now;
if (currentClickTime.Subtract(_recordedClick).TotalMilliseconds > 2000 ) {
_recordedClick = currentClickTime;
lblClick.Text = currentClickTime.ToString();
// TODO: add code to record this click
}
}
}
}
Designer:
namespace RecordClicks {
partial class Form1 {
/// <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.button1 = new System.Windows.Forms.Button();
this.lblClick = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(121, 241);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(132, 53);
this.button1.TabIndex = 0;
this.button1.Text = "Clicker";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// lblClick
//
this.lblClick.AutoSize = true;
this.lblClick.Font = new System.Drawing.Font("Segoe UI", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.lblClick.Location = new System.Drawing.Point(121, 127);
this.lblClick.Name = "lblClick";
this.lblClick.Size = new System.Drawing.Size(90, 45);
this.lblClick.TabIndex = 1;
this.lblClick.Text = "Time";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.lblClick);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Clicker Test";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button button1;
private Label lblClick;
}
}
I have made a sample project after my customers reported a graphical glitch in my software and I managed to reproduce the problem with ease. I create a simple docked DataGridView in a form and I fill it with random data like this:
var ds = new DataSet();
var table = ds.Tables.Add();
Enumerable.Range(0, 100).ForEach(i => table.Columns.Add(i.ToString()));
Enumerable.Range(0, 100).ForEach(i =>
{
var row = table.NewRow();
Enumerable.Range(0, 100).ForEach(j => row[j.ToString()] = Guid.NewGuid().ToString());
table.Rows.Add(row);
});
dataGridView1.DataSource = table;
Now I launch my program, move the window so that a part of it is covered by my taskbar and use a scrollbar. Suddenly all the data is messed up:
UPDATE:
partial class Form1
{
/// <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.dataGridView1 = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView1.Location = new System.Drawing.Point(0, 0);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(986, 758);
this.dataGridView1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(986, 758);
this.Controls.Add(this.dataGridView1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
}
What is the reason behind this?
So as a solution the .Invalidate() method can be used. Although it is not the best way. More about invalidate method can be found here:
https://msdn.microsoft.com/en-us/library/598t492a(v=vs.110).aspx
in my case the issue was that
some DataGridView cells background color were set to transparent
g[x,y].Style.BackColor = Color.Transparent;
I am developing a windows forms application for Windows Mobile 6 in Visual Studio 2008. There is a requirement to have some common controls on each form, such as Logo (PictureBox), Title (Label) and a small description (also Label). I decided to make a FormBase with those controls and inherit other forms from that base.
The problem is that for some reason, when I drop a Button or another control on that inherited form, I cannot resize it with my mouse. I can press Shift+Arrow to resize anything with my keyboard shortcuts, but the mouse does not work.
It's not very convenient neither for me nor for other developers in my team.
Any suggestions?
Update 1
the base form:
public class FormBase : Form
{
public FormBase()
{
InitializeComponent();
}
/// <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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBase));
this.pictureLogo = new System.Windows.Forms.PictureBox();
this.labelTitle = new System.Windows.Forms.Label();
this.panelSeparator = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// pictureLogo
//
this.pictureLogo.Image = ((System.Drawing.Image)(resources.GetObject("pictureLogo.Image")));
this.pictureLogo.Location = new System.Drawing.Point(0, 0);
this.pictureLogo.Name = "pictureLogo";
this.pictureLogo.Size = new System.Drawing.Size(48, 48);
//
// labelTitle
//
this.labelTitle.Font = new System.Drawing.Font("Tahoma", 10F, System.Drawing.FontStyle.Bold);
this.labelTitle.ForeColor = System.Drawing.Color.Black;
this.labelTitle.Location = new System.Drawing.Point(54, 2);
this.labelTitle.Name = "labelTitle";
this.labelTitle.Size = new System.Drawing.Size(183, 16);
this.labelTitle.Text = "Title";
//
// panelSeparator
//
this.panelSeparator.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panelSeparator.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(35)))), ((int)(((byte)(44)))), ((int)(((byte)(75)))));
this.panelSeparator.Location = new System.Drawing.Point(3, 50);
this.panelSeparator.Name = "panelSeparator";
this.panelSeparator.Size = new System.Drawing.Size(234, 1);
//
// FormBase
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.AutoScroll = true;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(240, 320);
this.ControlBox = false;
this.Controls.Add(this.panelSeparator);
this.Controls.Add(this.labelTitle);
this.Controls.Add(this.pictureLogo);
this.ForeColor = System.Drawing.Color.Black;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.KeyPreview = true;
this.Location = new System.Drawing.Point(0, 0);
this.MinimizeBox = false;
this.Name = "FormBase";
this.Text = "FormBase";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox pictureLogo;
private System.Windows.Forms.Label labelTitle;
private System.Windows.Forms.Panel panelSeparator;
}
the inherited form:
public class FrontDoorForm : FormBase
{
public FrontDoorForm()
{
InitializeComponent();
}
private void buttonQuit_Click(object sender, EventArgs e)
{
Close();
}
/// <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.buttonQuit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// buttonQuit
//
this.buttonQuit.Location = new System.Drawing.Point(3, 54);
this.buttonQuit.Name = "buttonQuit";
this.buttonQuit.Size = new System.Drawing.Size(115, 46);
this.buttonQuit.TabIndex = 2;
this.buttonQuit.Text = "Quit";
this.buttonQuit.Click += new System.EventHandler(this.buttonQuit_Click);
//
// FrontDoorForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(240, 320);
this.Controls.Add(this.buttonQuit);
this.Font = new System.Drawing.Font("Tahoma", 10F, System.Drawing.FontStyle.Regular);
this.ForeColor = System.Drawing.Color.Black;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Location = new System.Drawing.Point(0, 0);
this.MinimizeBox = true;
this.Name = "FrontDoorForm";
this.Text = "FrontDoorForm";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Controls.SetChildIndex(this.buttonQuit, 0);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button buttonQuit;
}
Just to close the question I will quote the answer from the comment:
Change the base form's WindowState back to Normal for a workaround. You can still get it Maximized in the derived form. Hans Passant
I cannot figure out how to get the MouseDown event when the mouse is down/clicked on the border of a Form. It is easy to see that it is raised when the mouse is down in the (I think its called) client area of the form, but it is never raised when it is down on the border.
Here is a SSCCE that demonstrates the issue. The label in the center of the form is only changed when the mouse is down on the client area and not the border.
Is there anyway to catch this event or have it be raised?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MouseEventTest
{
public partial class Form1 : Form
{
Random rand = new Random();
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
label1.Text = rand.Next().ToString();
}
/// <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.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(42, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(91, 13);
this.label1.TabIndex = 0;
this.label1.Text = "99999999999999";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(185, 75);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
}
}
EDIT: I have solved this problem, but it created another. If you are visting this question in the future here is a related question I asked. It (hopefully) will help me/us figure out when the mouse has been released too. WM_NCLBUTTONUP message not sent at the end of dragging a form, how to do so?
Override the WndProc method:
const int WM_NCLBUTTONDWN = 0xA1;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCLBUTTONDWN)
{
this.Text = "got it!";
}
base.WndProc(ref m);
}
Use this method and calculate for the border of your form. There's no way to handle it via "Form" because the border is not a part of the Form...
EDIT1:
As commented by Lars, there's no way to do this using WinForms. You will need to "go down" a floor and work with the WinForms infrastructure...
I'm using Visual Studio 2010 to create an application. I have a class derived from the System.Windows.Forms.Form control. This class, called CViewport, is a standard for all forms in my application( ie. I intend to derive other forms from this class).
After deriving a class from CViewport, I go to the designer to edit the 2nd generation form and in the designer the form is not displayed correctly. It appears transparent if I'm not mistaken...the previous window shines through the client area of the form as if the backbuffer has not been drawn to by the designer...
...Also, after changing the size of the 2nd gen form, the designer resets the size to arbitrary dimensions...
Why might this be happening? Here is Form derived class:
namespace MyApp
{
public partial class CViewport : Form
{
public CViewport()
{
InitializeComponent();
}
}
}
here is CViewport.Designer.cs:
namespace MyApp
{
partial class CViewport
{
/// <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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GDEViewport));
this.SuspendLayout();
//
// CViewport
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 600);
this.ControlBox = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "GDEViewport";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Activated += new System.EventHandler(this.ViewportForm_Activated);
this.Deactivate += new System.EventHandler(this.ViewportForm_Deactivate);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.OnFormClosing);
this.ResizeBegin += new System.EventHandler(this.ViewportForm_ResizeBegin);
this.ResizeEnd += new System.EventHandler(this.ViewportForm_ResizeEnd);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.ViewportForm_Paint);
this.Resize += new System.EventHandler(this.MainViewport_UserResized);
this.ResumeLayout(false);
}
#endregion
}
}
here is 2nd gen form derived from CViewport
namespace MyApp
{
public partial class CMainViewport: CViewport
{
public CMainViewport()
{
InitializeComponent();
}
}
}
here is CMainViewport.Designer.cs:
namespace MyApp
{
partial class CMainViewport
{
/// <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.SuspendLayout();
//
// CMainViewport
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1218, 573);
this.ControlBox = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
this.MaximizeBox = true;
this.MinimizeBox = true;
this.MinimumSize = new System.Drawing.Size(800, 600);
this.Name = "TestForm";
this.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.ShowIcon = true;
this.ShowInTaskbar = true;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Auto;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "TestForm";
this.PauseRendering += new System.EventHandler<System.EventArgs>(this.ViewportForm_PauseRendering);
this.ResumeRendering += new System.EventHandler<System.EventArgs>(this.ViewportForm_ResumeRendering);
this.SystemResume += new System.EventHandler<System.EventArgs>(this.MainViewport_SystemResume);
this.SystemSuspend += new System.EventHandler<System.EventArgs>(this.MainViewport_SystemSuspend);
this.UserResized += new System.EventHandler<System.EventArgs>(this.MainViewport_UserResized);
this.Activated += new System.EventHandler(this.ViewportForm_Activated);
this.Deactivate += new System.EventHandler(this.ViewportForm_Deactivate);
this.ResizeBegin += new System.EventHandler(this.ViewportForm_ResizeBegin);
this.ResizeEnd += new System.EventHandler(this.ViewportForm_ResizeEnd);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.ViewportForm_Paint);
this.Resize += new System.EventHandler(this.ViewportForm_Resize);
this.ResumeLayout(false);
}
#endregion
}
}
this.ResizeBegin += new System.EventHandler(this.ViewportForm_ResizeBegin);
this.ResizeEnd += new System.EventHandler(this.ViewportForm_ResizeEnd);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.ViewportForm_Paint);
this.Resize += new System.EventHandler(this.MainViewport_UserResized);
The designer runs the code in the base class to provide the WYSIWYG view. That's normally the Form class, it doesn't have any bugs. Now it is your CViewPort class. It has bugs. In one those event handlers that we cannot see.
Like the Paint event handler, strong lead to "is not displayed correctly". You have a handler for Resize, strong lead to "resets the size to arbitrary dimensions". Having these events also run at design time is what is getting you into trouble. And you are doing it wrong, a base class for a Form should override OnPaint() and OnResize() so the order in which code runs is predictable and controllable.
Having code run at design-time requires deeper insight in the way Winforms works, getting guidance from a book is rather important. You are not there yet, you didn't realize that posting the code for these event handlers was even relevant. There's a keep-out-of-trouble approach that gives you time to read the book, add this line of code to every event handler you added to your CViewPort class:
if (this.DesignMode) return;
The answer posted by Hans Passant was very helpful...the problem though, was that I was setting the DockStyle property of the base class to 'Fill' in the base form's constructor. Removing this line of code fixed the problem...