1.新建三个窗体:
2.MainForm主窗体代码如下:
private MaskForm _shadowForm;
/// <summary>
/// 显示遮罩层
/// </summary>
private void ShowMask()
{
_shadowForm = new ShadowForm(this.Location,this.Size);
_shadowForm.Show();
}
/// <summary>
/// 关闭遮罩层
/// </summary>
private void HideMask()
{
if (_shadowForm != null)
{
_shadowForm.Close();
}
}
/// <summary>
/// 放大视频显示画面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pbCamera1_Click(object sender, EventArgs e)
{
MessageForm msgFrm = new MessageForm(m_lUserID1);
msgFrm.HideMaskAction += () => {
this.HideMask();
};
this.ShowMask();
if (msgFrm.ShowDialog() == DialogResult.OK)
{
this.HideMask();
msgFrm.Dispose();
}
}
3.MessageForm主窗体代码如下:
public Action HideMaskAction { get; set; }
private void lbClose_Click(object sender, EventArgs e)
{
this.HideMaskAction();
}
private void PictureZoomForm_FormClosed(object sender, FormClosedEventArgs e)
{
this.DialogResult = DialogResult.OK;
}
4.MaskForm主窗体代码如下:
public MaskForm(Point point, Size size)
{
InitializeComponent();
this.Opacity = 0.5;
this.BackColor = Color.LightGray;
this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPosition.Manual;
//位置和大小跟随主界面
this.Location = point;
this.Size = size;
}
private void MaskForm_FormClosed(object sender, FormClosedEventArgs e)
{
this.Dispose();
}
此代码借鉴未来大大的文章,路径为:https://blog.csdn.net/qq_30725967/article/details/126540576
标签:遮罩,MaskForm,void,object,shadowForm,private,弹窗,WinForm From: https://www.cnblogs.com/bingsying/p/17429698.html