已有56人关注
关于子窗体在父窗体中的显示问题
发表在C#图书答疑 2014-03-29
是否精华
版块置顶:
以下是我编写的一段程序,目的是为了在父窗体“Form1”中显示子窗体“Form2”。可是实现以后,为什么“Form2”显示的时候,被“Form1”中的按钮给部分遮住了,而不能实现“Form2”在“Form1”中的最前端显示。
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 Chapter12part1
{
    public partial class Form1 : Form
    {
        Form2 f2 = new Form2();                 
       
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            IsMdiContainer = true;                       
            button1.Text = "打开 Form2";
            button2.Text = "隐藏 Form2";
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //this.Hide();                              
            if (MessageBox.Show("是否打开'Form2'", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
            {
                f2.Show();                                
                f2.MdiParent = this;
               
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            f2.Hide();                              //隐藏“窗体2”
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
分享到:
精彩评论 1
小科_mrkj
学分:43 LV2
2014-04-04
沙发
读者朋友:
    您好,不要把窗体设成父子窗体,直接调用Show方法显示Form2。
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照