Handle the Click event for the add and remove buttons:
private Button runTimeButton = null;
private void butAdd_Click(object sender, EventArgs e)
{
Button but = sender as Button;
if (but != null)
{
if (runTimeButton == null)
{
runTimeButton = new Button();
runTimeButton.Text = "Added!";
runTimeButton.Location = new Point(but.Location.X, but.Location.Y + 30);
runTimeButton.Click += new EventHandler(runTimeButton_Click);
Controls.Add(runTimeButton);
}
}
}
void runTimeButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Added Button Clicked!");
}
private void butRemove_Click(object sender, EventArgs e)
{
if (runTimeButton != null)
{
Controls.Remove(runTimeButton);
runTimeButton.Click -= runTimeButton_Click;
runTimeButton = null;
}
}
However, if you are looking at the user adding lots of information, you might want to consider using a DataGridView instead - it is designed for the user to add and remove rows.
When it comes to printing, don't let users move anything!
Don't try to print the actual form - it will look horrible. Instead, use the
PrintDocument class[
^] to handle your print outs - it gives you full control over what and where things are printed, including fonts, sizes, colours, etc., which do not have to be related in any way to the screen display.