【发布时间】:2012-10-19 11:49:39
【问题描述】:
我有以下两段代码,请看一下,我指出了哪里出错了。 我删除了调用第二个窗口的函数,它们在这里没有意义。
第一,主窗体,这个窗体调用第二个窗体:
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;
using System.Runtime.InteropServices;
namespace STP_Design
{
public partial class STP2Main : Form
{
public STP2Main()
{
InitializeComponent();
tabControl1.SelectedTab = tabPageDeviceManager;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
MenuForm MDIMF = new MenuForm();
MDIMF.MdiParent = this;
MDIMF.StartPosition = FormStartPosition.Manual;
MDIMF.Location = new Point(3, 50);
MDIMF.Show();
tabControl1.Visible = false;
}
public void set()
{
tabControl1.Visible = true; // This statement executes, but does not result in anything I'd expect. The debugger tells me the visibility is false.
tabControl1.BringToFront();
}
}
}
第二个表单,我关闭并更新第一个表单:
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 STP_Design
{
public partial class MenuForm : Form
{
public MenuForm()
{
InitializeComponent();
this.BringToFront();
}
private void button1_Click(object sender, EventArgs e)
{
STP2Main stp = new STP2Main();
stp.set();
this.Close();
}
}
}
【问题讨论】:
-
您看到的行为是什么?
-
“调用第二个窗口”代码可能非常重要。
-
实际显示 STP2Main 的代码在哪里?
-
我在打开第二个表单时使我的 tabcontrol 框不可见,如果我关闭表单并尝试使 tabcontrol 可见,它根本不会出现。我在应该设置可见性的行上设置了一个断点。它说它不可见(没错)但仍然不可见......
-
我再添加一些代码,1 秒
标签: c# winforms function public