1

I'm rewriting a program originally written in FoxPro that is used by town and school tax collectors. Unfortunately, I'm learning this as I go. The program requires windows to be modal - the users follow a specific path, and can't play with more than one window at a time. I have a MDI container form that I open. All child forms are called from there. Right now, I don't maximize the child forms, and it looks like this:

enter image description here

You can see the scroll bars, as it's not maximized. I don't really want them to deal with scroll bars... so I go into my form Login, the child form, and set WindowState to maximized. I get this:

enter image description here

The scroll bars are gone, the child window fits perfectly in the container window, but there are two control bars at the top... the main one for the container, and a second smaller one for the child form, with the second one having double controls on it. I've tried setting MaximizeBox, MinimizeBox, ShowIcon, and ControlBox to false, and have deleted the Text for the child form, and yet that bar is still there. If I click on certain buttons on the smaller bar, the duplicates go away. I'm looking for a way to get rid of the second bar, or hide the controls on it... or anything I haven't thought of that can help.

Chris Pfohl
  • 18,220
  • 9
  • 68
  • 111

1 Answers1

6

Why not use UserControls then you can add/remove them from your Main Form, they won't have the overhead that you have with Mdi Forms.

A quick and dirty example you will want to setup property's and events on the UserControl to pass data to and from your main form:

Form1

public partial class Form1 : Form
{
    UserControl1 login = new UserControl1();
    public Form1()
    {
        InitializeComponent();
        login.ExitEvent += new UserControl1.ExitEventHandler(login_ExitEvent);

    }

    void login_ExitEvent(object sender, EventArgs e)
    {
        panel1.Controls.Remove(login);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        panel1.Controls.Add(login);
        login.BringToFront();
    }
}

UserControl

public partial class UserControl1 : UserControl
{
    public delegate void ExitEventHandler(object sender, EventArgs e);
    public event ExitEventHandler ExitEvent; 

    public UserControl1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        ExitEvent(this, new EventArgs());
    }
}
Mark Hall
  • 53,938
  • 9
  • 94
  • 111
  • 1
    @user1442499 I agree with Mark. MDI is a tool with a very specific use-case. If you try to use it any other way, you are going to continue to encounter annoying details which you will struggle to work around. – Tergiver Jun 07 '12 at 15:38
  • Mark, thank you, thank you, thank you. I think this is what I've been searching for. I just wish I'd asked before creating 18 forms. +laugh+ Lars, I did see the answer to move it to the Load event, but doing so did not help. Still, thanks everyone, I can't tell you how much I appreciate this. – user1442499 Jun 07 '12 at 16:20