/// <summary> /// Set whether the glass should be extended into the client space. /// </summary> /// <param name="form">The <see cref="System.Windows.Forms.Form"/> to be extended.</param> /// <param name="value">The enabled value.</param> public void SetGlassEnabled(Form form, bool value) { GlassFormProperties prop = GetFormProperties(form); prop.GlassEnabled = value; GlassifyForm(form); }
/// <summary> /// Sets the glass margins. /// </summary> /// <param name="form">The <see cref="System.Windows.Forms.Form"/> to be extended.</param> /// <param name="value">The margins where the glass will be extended.</param> public void SetGlassMargins(Form form, Padding value) { if (form == null) { throw new ArgumentNullException("form"); } GlassFormProperties prop = GetFormProperties(form); if (value == null || value == Padding.Empty) { prop.GlassMargins = Padding.Empty; UnhookForm(form); } else { prop.GlassMargins = value; form.Paint += new PaintEventHandler(form_Paint); if (!form.IsDesignMode()) { form.MouseDown += new MouseEventHandler(form_MouseDown); form.MouseMove += new MouseEventHandler(form_MouseMove); form.MouseUp += new MouseEventHandler(form_MouseUp); form.Resize += new EventHandler(form_Resize); form.Shown += new EventHandler(form_Shown); } } form.Invalidate(); }
private void form_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { GlassFormProperties prop = GetFormProperties(sender as Form); prop.FormMoveTracking = false; } }
private GlassFormProperties GetFormProperties(Form form) { if (!formProps.TryGetValue(form, out var prop)) { formProps.Add(form, prop = new GlassFormProperties()); } return(prop); }
private static Rectangle GetNonGlassArea(Form form, GlassFormProperties prop) { if (prop == null) { return(form.ClientRectangle); } return(new Rectangle(form.ClientRectangle.Left + prop.GlassMargins.Left, form.ClientRectangle.Top + prop.GlassMargins.Top, form.ClientRectangle.Width - prop.GlassMargins.Horizontal, form.ClientRectangle.Height - prop.GlassMargins.Vertical)); }
private void form_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { GlassFormProperties prop = GetFormProperties(sender as Form); if (prop.GlassMarginMovesForm) { prop.FormMoveTracking = true; prop.FormMoveLastMousePos = ((Control)sender).PointToScreen(e.Location); } } }
private void form_MouseMove(object sender, MouseEventArgs e) { GlassFormProperties prop = GetFormProperties(sender as Form); if (prop.FormMoveTracking && !GetNonGlassArea(sender as Form, prop).Contains(e.Location)) { Point screen = ((Control)sender).PointToScreen(e.Location); Point diff = new Point(screen.X - prop.FormMoveLastMousePos.X, screen.Y - prop.FormMoveLastMousePos.Y); Point loc = ((Control)sender).Location; loc.Offset(diff); ((Control)sender).Location = loc; prop.FormMoveLastMousePos = screen; } }
/// <summary> /// Sets a value indicating whether clicking and dragging within the margin will move the form. /// </summary> /// <param name="form">The <see cref="System.Windows.Forms.Form"/> to be extended.</param> /// <param name="value"><c>true</c> if clicking and dragging within the margin moves the form; otherwise, <c>false</c>.</param> public void SetGlassMarginMovesForm(Form form, bool value) { GlassFormProperties prop = GetFormProperties(form); prop.GlassMarginMovesForm = value; }
private Rectangle GetNonGlassArea(Form form, GlassFormProperties prop) { if (prop == null) return form.ClientRectangle; return new Rectangle(form.ClientRectangle.Left + prop.GlassMargins.Left, form.ClientRectangle.Top + prop.GlassMargins.Top, form.ClientRectangle.Width - prop.GlassMargins.Horizontal, form.ClientRectangle.Height - prop.GlassMargins.Vertical); }
private GlassFormProperties GetFormProperties(Form form) { GlassFormProperties prop; if (!formProps.TryGetValue(form, out prop)) formProps.Add(form, prop = new GlassFormProperties()); return prop; }