76 lines
2.1 KiB
C#
76 lines
2.1 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Drawing;
|
|||
|
using System.Data;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
|
|||
|
namespace AppLauncher.Windows.Forms
|
|||
|
{
|
|||
|
public partial class TitlePanel : UserControl
|
|||
|
{
|
|||
|
private bool windowDragging = false;
|
|||
|
private Point windowOffset = new Point();
|
|||
|
|
|||
|
public TitlePanel()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
|
|||
|
protected override void OnParentBindingContextChanged(EventArgs e)
|
|||
|
{
|
|||
|
base.OnParentBindingContextChanged(e);
|
|||
|
|
|||
|
if (this.Parent != null)
|
|||
|
{
|
|||
|
if (this.Parent.GetType() == typeof(MainForm))
|
|||
|
{
|
|||
|
pictureBox1.MouseDown += parentForm_MouseDown;
|
|||
|
pictureBox1.MouseUp += parentForm_MouseUp;
|
|||
|
pictureBox1.MouseMove += parentForm_MouseMove;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[Category("Appearance"), Browsable(true)]
|
|||
|
public string TitleText
|
|||
|
{
|
|||
|
get => label1.Text;
|
|||
|
set => label1.Text = value;
|
|||
|
}
|
|||
|
|
|||
|
protected void parentForm_MouseDown(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
if (e.Button != MouseButtons.Left)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
windowDragging = true;
|
|||
|
windowOffset = e.Location;
|
|||
|
}
|
|||
|
|
|||
|
protected void parentForm_MouseUp(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
windowDragging = false;
|
|||
|
}
|
|||
|
|
|||
|
protected void parentForm_MouseMove(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
if (windowDragging)
|
|||
|
{
|
|||
|
Point pos = this.PointToScreen(e.Location);
|
|||
|
|
|||
|
int y = Math.Max((pos.Y - windowOffset.Y), Screen.PrimaryScreen.WorkingArea.Y);
|
|||
|
y = Math.Min(y, (Screen.PrimaryScreen.WorkingArea.Y + Screen.PrimaryScreen.WorkingArea.Height) - this.Height);
|
|||
|
|
|||
|
this.Parent.Location = new Point(Screen.PrimaryScreen.WorkingArea.X, y);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|