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 POSV { public partial class TransparentFormExt : BaseForm { /// /// 当前业务处理窗口 /// private BusinessForm form; /// /// 遮罩层窗体 /// 当前位置 /// 窗体大小 /// 窗体 public TransparentFormExt(Control overlay , BusinessForm form) : this(overlay , Constant.Opacity , form) { } public TransparentFormExt(Control overlay , double opacity , BusinessForm form) { InitializeComponent(); this.Name = "TransparentFormExt"; //无边框 this.FormBorderStyle = FormBorderStyle.None; //透明度 this.Opacity = opacity; //最大化/最小化 this.MaximizeBox = false; this.MinimizeBox = false; this.ShowIcon = false; this.ShowInTaskbar = false; //窗口位置和大小 this.StartPosition = FormStartPosition.Manual; Rectangle rect = new Rectangle(overlay.PointToScreen(Point.Empty) , overlay.Size); this.Location = new Point(rect.X , rect.Y); this.Size = new Size(rect.Width , rect.Height); //当前窗体 this.form = form; } private bool isShow = false; protected override void OnActivated(EventArgs e) { try { base.OnActivated(e); if (isShow) return; //工作窗体最大化、最小化 this.form.MaximizeBox = false; this.form.MinimizeBox = false; this.form.ShowIcon = false; this.form.ShowInTaskbar = false; //DockStyle this.form.Dock = DockStyle.Fill; this.form.Owner = this; //工作窗体显示 this.form.Show(this); this.form.BringToFront(); this.form.Activate(); this.form.Focus(); this.isShow = true; } catch(Exception ex) { LOGGER.Error(ex , "OnActivated异常"); } } protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (this.form != null) { this.form.BringToFront(); this.form.Activate(); this.form.Focus(); } } protected override void OnFormClosing(FormClosingEventArgs e) { if (this.Owner != null) { this.Owner.Activate(); } isShow = false; this.Visible = false; e.Cancel = true; } } }