a 首先添加一个ContextMenuStrip,写两个菜单“全屏显示”和“取消全屏”,写菜单的MousDown事件如下:
private void 全屏显示ToolStripMenuItem_MouseDown(object sender, MouseEventArgs e)
{
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
FillScreenbtn.Text = "退出全屏";
}
private void 退出全屏ToolStripMenuItem_MouseDown(object sender, MouseEventArgs e)
{
this.TopMost = false;
this.FormBorderStyle = FormBorderStyle.Sizable;
this.WindowState = FormWindowState.Normal;
FillScreenbtn.Text = "全屏";
}
然后写鼠标的右击事件,由于我把picturebox控件在父窗口停靠了,所以就写picturebox的事件,如下:
{
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
FillScreenbtn.Text = "退出全屏";
}
private void 退出全屏ToolStripMenuItem_MouseDown(object sender, MouseEventArgs e)
{
this.TopMost = false;
this.FormBorderStyle = FormBorderStyle.Sizable;
this.WindowState = FormWindowState.Normal;
FillScreenbtn.Text = "全屏";
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right && FillScreenbtn.Text == "全屏")
{
退出全屏ToolStripMenuItem.Enabled = false;
全屏显示ToolStripMenuItem.Enabled = true;
}
else
{
退出全屏ToolStripMenuItem.Enabled = true;
全屏显示ToolStripMenuItem.Enabled = false;
}
}
其中FillScreenbtn只是作为是否全屏的一个标识。{
if (e.Button == MouseButtons.Right && FillScreenbtn.Text == "全屏")
{
退出全屏ToolStripMenuItem.Enabled = false;
全屏显示ToolStripMenuItem.Enabled = true;
}
else
{
退出全屏ToolStripMenuItem.Enabled = true;
全屏显示ToolStripMenuItem.Enabled = false;
}
}