本文介绍了我想在C#中从ChildForm访问ParentForm的面板控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ParentForm上有面板控件,我在panl控件上打开了ChildForm,从ChildForm我想在ParentForm的面板控件上打开ThirdForm





i在ChildForm按钮上使用此代码



i have panel control on ParentForm, i opened the ChildForm on panl control and from ChildForm i want to open ThirdForm on panel control of ParentForm


i used this code on the button of ChildForm

ParentForm panel = new ParentForm();
panel.panel_Main.Controls.Clear();
ThirdForm third = new ThirdForm();
third.TopLevel = false;
third.AutoScroll = true;
third.Dock = DockStyle.Fill;
panel.panel_Main.Controls.Add(third);
student.Show();

推荐答案


((System.Windows.Forms.Panel)Application.OpenForms["ParentForm"].Controls["panel_Main"]).Controls.Clear();
                    ThirdForm third = new ThirdForm();
                    third.TopLevel = false;
                    third.AutoScroll = true;
                    third.Dock = DockStyle.Fill;
                  ((System.Windows.Forms.Panel)Application.OpenForms["ParentForm"].Controls["panel_Main"]).Controls.Add(student);
                    third.Show();


这篇关于我想在C#中从ChildForm访问ParentForm的面板控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 02:42