如何显示动态创建的用户控件?
How to get Dynamically Created User Control to show?
我有一个名为 home 的用户控件,它已经设置了位置。当我在下面动态创建它时,我看不到它。我已经尝试使用 show and bring to front 方法将 属性 设置为可见,但没有任何效果。我错过了什么?
namespace TipManager {
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
form = new Form1();
Application.Run(form);
TipManagerModel tipManager = new TipManagerModel();
TipManagerServices services = new TipManagerServices(tipManager);
Home homeView = new Home();
HomePresenter homePresenter = new HomePresenter(homeView, tipManager, services);
form.Controls.Add(homeView);
homeView.BringToFront();
}
static Form1 form;
} }
添加控件之前正在调用窗体,将Application.Run(form);
移动到函数的末尾。附带一提,我强烈建议在 InitializeComponents();
之后的表单构造函数中执行此操作,而不是在此处执行此操作。
我有一个名为 home 的用户控件,它已经设置了位置。当我在下面动态创建它时,我看不到它。我已经尝试使用 show and bring to front 方法将 属性 设置为可见,但没有任何效果。我错过了什么?
namespace TipManager { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); form = new Form1(); Application.Run(form); TipManagerModel tipManager = new TipManagerModel(); TipManagerServices services = new TipManagerServices(tipManager); Home homeView = new Home(); HomePresenter homePresenter = new HomePresenter(homeView, tipManager, services); form.Controls.Add(homeView); homeView.BringToFront(); } static Form1 form; } }
添加控件之前正在调用窗体,将Application.Run(form);
移动到函数的末尾。附带一提,我强烈建议在 InitializeComponents();
之后的表单构造函数中执行此操作,而不是在此处执行此操作。