如何在按钮上显示两个子窗体单击C#.net中的父窗体 [英] how to display two child forms on a button click in a parentform in C#.net

查看:62
本文介绍了如何在按钮上显示两个子窗体单击C#.net中的父窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在按钮上显示两个子窗体,然后在C#.net中单击父窗体.

我必须在单击按钮时显示两个子窗体.这些子窗体对象是在父窗体加载中创建的,并且两个窗体在父窗体中给出,这些子窗体对象添加到了面板属性中.但是,仅显示一个子窗体.
在parentform加载中,给出以下代码:

how to display two child forms on a button click in a parentform in C#.net.

I have to display two child forms on a button click.These child forms objects are created in the parentform load and two panels are given in the parent form,rhese childform objects are added to the panel attributes.But only one child form is displaying.
In the parentform load,the below code is given:

TextToSpeak Sform = new TextToSpeak();
Sform.TopLevel = false;
Sform.Dock = DockStyle.Fill;
Sform.TopMost = false;
panel1.Controls.Add(Sform);
Sform.Parent = this;
Sform.ShowIcon = true;
Sform.FormBorderStyle = FormBorderStyle.Fixed3D;
Sform.BringToFront();
Sform.Show();

ChatBot Cform = new ChatBot();
Cform.Dock = DockStyle.Fill;
Cform.TopMost = false;
Cform.TopLevel = false;
panel2.Controls.Add(Cform);

Cform.Parent = this;
Cform.ShowIcon = true;
Cform.FormBorderStyle = FormBorderStyle.Fixed3D;
Cform.BringToFront();
Cform.Show();

推荐答案

您好,

就个人而言,我会使用用户控件而不是表单来做到这一点.

Hello,

Personally I would use usercontrols rather than forms to do that.

UserControl1 userControl1 = new UserControl1();
UserControl2 userControl2 = new UserControl2();
this.panel1.Controls.Add(userControl1);
this.panel2.Controls.Add(userControl2);
userControl1.Dock = DockStyle.Fill;
userControl2.Dock = DockStyle.Fill;




Valery.




Valery.


您已将Dock设置为Fill.这意味着一种形式将在另一种之上.这就是为什么您看不到两者的原因.
我假设您正在尝试创建MDI应用程序.正确设置开始位置,并且不要将Dock设置为Fill.
You''ve set the Dock to Fill. Which means that one form will be on top of the other. That''s why you can''t see both.

I assume you''re trying to create an MDI application. Set the start location correctly, and don''t set the Dock to Fill.


这篇关于如何在按钮上显示两个子窗体单击C#.net中的父窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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