110,571
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
if (this.button1.Text == "Full Screen")
{
Report f = new Report();
f.StartPosition = FormStartPosition.CenterScreen;
f.FormBorderStyle = FormBorderStyle.None;
f.WindowState = FormWindowState.Maximized;
f.button1.Text = "Exit Screen";
f.TopMost = true;
this.WeekList.Width = Screen.PrimaryScreen.WorkingArea.Width;
f.ShowDialog();
}
else
{
this.Dispose();
this.Close();
}
}
为什么要保证两个窗体同步,是因为在窗体操作更新了一些选项后,如果退出全屏后小窗体的选项想要保持在全屏后选择的那些状态。不知道要怎么操作?
Report frm=null;
private void button1_Click(object sender, EventArgs e)
{
if (this.button1.Text == "Full Screen")
{
Report f = new Report();
//引用自身
f.frm=this;
f.StartPosition = FormStartPosition.CenterScreen;
f.FormBorderStyle = FormBorderStyle.None;
f.WindowState = FormWindowState.Maximized;
f.button1.Text = "Exit Screen";
f.TopMost = true;
this.WeekList.Width = Screen.PrimaryScreen.WorkingArea.Width;
f.ShowDialog();
}
else
{
this.Dispose();
this.Close();
}
}
protected Form con = null;//保存父级容器
/// <summary>
/// 最大化
/// </summary>
protected void BaseFullScreen(out Form parentForm)
{
parentForm = this.ParentForm;//这里的this是要全屏的Form,这段代码是在这个Form里面写的,不是在主窗体里写的
MainForm main = parentForm as MainForm;//MainForm是主窗体
main.pnlMain.Controls.Remove(this);///这里在主窗体中把要全屏的部分,也就是this抠除
main.Visible = false;
this.TopLevel = true;
//this.TopMost = true;
//获取屏幕分辨率
int SH = Screen.PrimaryScreen.Bounds.Height;
int SW = Screen.PrimaryScreen.Bounds.Width;
this.Size = new Size(SW, SH);
//SetToolTipName();
this.Activate();
this.isFullScreen = true;
}
//要说明的是,上述代码要全屏的部分已经是一个Form了,所以就把大小和位置改了一下,如果不是Form而是UserControl或者是Panel之类的,就再新建一个全屏的Form把它放进去。
/// <summary>
/// 最大化还原
/// </summary>
protected void BaseReduction(Form parentForm)
{
if (parentForm != null)
{
//this.TopMost = false;
this.TopLevel = false;
this.Dock = DockStyle.Fill;
MainForm2 main = parentForm as MainForm2;
main.pnlMain.Controls.Add(this);//把这个Form塞回去
main.Visible = true;
this.isFullScreen = false;
//this.Focus();
}
}
/// <summary>
/// 窗体全屏
/// </summary>
protected override void TabFormFullScreen()
{
if (!isFullScreen)//全屏
{
this.picFullScreen.Image = global::MachineTeachUI.Properties.Resources.t6;//更换切换按钮图标
base.BaseFullScreen(out con);
this.ttVia.SetToolTip(this.picFullScreen,"还原");//设置切换按钮浮动显示内容
}
else//还原
{
this.picFullScreen.Image = global::MachineTeachUI.Properties.Resources.t5;
base.BaseReduction(con);
this.ttVia.SetToolTip(this.picFullScreen, "全屏");
con = null;
}
思路就是这样的。
[quote=引用 9 楼 qyj2009 的回复:]
全屏与否会改变控件的状态?
[quote=引用 6 楼 BenBenBears 的回复:] [quote=引用 3 楼 wg5945 的回复:] 为什么要2个窗口呢? 本身全屏不可以么?
[quote=引用 6 楼 BenBenBears 的回复:] [quote=引用 3 楼 wg5945 的回复:] 为什么要2个窗口呢? 本身全屏不可以么?
[quote=引用 3 楼 wg5945 的回复:] 为什么要2个窗口呢? 本身全屏不可以么?
为什么要2个窗口呢? 本身全屏不可以么?
[quote=引用 2 楼 sunzongbao2007 的回复:] 让两个窗口都具有 LoadData 方法, 当focus或者关闭其中一个时, 调用另一个的LoadData方法。 就酱啊
让两个窗口都具有 LoadData 方法, 当focus或者关闭其中一个时, 调用另一个的LoadData方法。 就酱啊