在 C# WinForms 中,我怎样才能摆脱孩子的控制栏? [英] in C# WinForms, how can I get rid of the child's control bar?

查看:16
本文介绍了在 C# WinForms 中,我怎样才能摆脱孩子的控制栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重写一个最初用 FoxPro 编写的程序,供城镇和学校税务员使用.不幸的是,我正在学习这个.该程序要求窗口是模态的——用户遵循特定的路径,并且一次不能玩多个窗口.我有一个我打开的 MDI 容器表单.从那里调用所有子窗体.现在,我没有最大化子窗体,它看起来像这样:

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:

您可以看到滚动条,因为它没有最大化.我真的不希望他们处理滚动条......所以我进入我的表单登录,子表单,并将 WindowState 设置为最大化.我明白了:

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:

滚动条消失了,子窗口完全适合容器窗口,但是顶部有两个控制条……主要的一个用于容器,第二个较小的用于子窗体,带有第二个有双重控制.我已经尝试将 MaximizeBox、MinimizeBox、ShowIcon 和 ControlBox 设置为 false,并删除了子窗体的 Text,但该栏仍然存在.如果我单击较小栏上的某些按钮,重复项就会消失.我正在寻找一种方法来摆脱第二个栏,或隐藏其上的控件...或任何我没有想到的方法都可以提供帮助.

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.

推荐答案

为什么不使用 UserControls,那么您可以在主窗体中添加/删除它们,它们不会像使用 Mdi 窗体那样产生开销.

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.

一个简单粗暴的示例,您需要在 UserControl 上设置属性和事件,以便将数据传入和传出主窗体:

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();
    }
}

用户控件

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());
    }
}

这篇关于在 C# WinForms 中,我怎样才能摆脱孩子的控制栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆