Hi all!
I'm creating a program that opens a small form for each row in a database (each form is an instance of Notebox). The user can create a new Notebox by clicking on a button (noteboxSibling) at the bottom of each existing Notebox. All Noteboxes exist inside Form1 which has been expanded to fill the entire screen.
My problem is that right now when you click on the button to make a new Notebox (noteboxSibling), it creates the new Notebox INSIDE the existing Notebox. My attempts to get the new Notebox to appear inside Form1 have so far all been failures. I can get a new Notebox to appear outside of both Form1 and the 'parent' Notebox, or inside of the 'parent' Notebox, but not inside of Form1 (as a 'peer' to the existing Noteboxes).
I hope I haven't made a mess of explaining that... I'm obviously doing something very silly. I've searched many forums for help with this problem and could only find a few tertiary related solutions.
Here's the code I'm currently using (I'm running .NET4 and VisualStudio 2010):
For Form1.cs:
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 Kimpl
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Notebox noteboxSibling = new Notebox();
noteboxSibling.TopLevel = false; // Renders the new Notebox instance a non top level control, making it sit inside Form1
this.Controls.Add(noteboxSibling); // Adds new Notebox instance to form as a control
noteboxSibling.Show(); // Shows the new Notebox instance
}
}
}
And for Notebox.cs:
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 Kimpl
{
public partial class Notebox : Form
{
public Notebox()
{
InitializeComponent();
}
private void boxenBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.boxenBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.noteboxDataSet);
}
private void Notebox_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'noteboxDataSet.boxen' table. You can move, or remove it, as needed.
this.boxenTableAdapter.Fill(this.noteboxDataSet.boxen);
}
private void noteBoxSibling_Click(object sender, EventArgs e)
{
Notebox noteboxSibling = new Notebox();
noteboxSibling.TopLevel = false; // Renders the new Notebox instance a non top level control, making it sit inside Form1
this.Controls.Add(noteboxSibling); // Adds new Notebox instance to form as a control
noteboxSibling.Show(); // Shows the new Notebox instance
noteBoxSibling.BringToFront(); // Focuses on the new Notebox instance
}
}
}
Thank you so much for reading this. I'm still trying to learn enough to not be dangerous ;)