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; using System.Diagnostics; namespace AppLauncher.Windows.Forms { public partial class TilePanel : AUserControl { protected bool isDragging = false; protected Point startPosition = new Point(); public TilePanel() : base() { InitializeComponent(); this.MouseDown += panel_MouseDown; this.MouseUp += panel_MouseUp; this.MouseMove += panel_MouseMove; pictureBox1.MouseDown += panel_MouseDown; pictureBox1.MouseUp += panel_MouseUp; pictureBox1.MouseMove += panel_MouseMove; label1.MouseDown += panel_MouseDown; label1.MouseUp += panel_MouseUp; label1.MouseMove += panel_MouseMove; } protected override void OnLocationChanged(EventArgs e) { base.OnLocationChanged(e); if (this.Parent != null) { if (this.Parent.GetType() == typeof(TilePanelContainer)) { TilePanelContainer container = (TilePanelContainer)this.Parent; Point p = container.GetTilePosition(this.Location); //label1.Text = p.X.ToString() + ", " + p.Y.ToString(); } } } [Category("Appearance"), Browsable(true)] public string TitleText { get => label1.Text; set => label1.Text = value; } [Category("Appearance"), Browsable(true)] public Image IconImage { get => pictureBox1.BackgroundImage; set => pictureBox1.BackgroundImage = value; } [Browsable(false)] public string ProcessFilename { get; set; } [Browsable(false)] public string ProcessArgument { get; set; } [Browsable(false)] public string ProcessWorkingDirectory { get; set; } [Browsable(false)] public ProcessWindowStyle ProcessWindowStyle { get; set; } = ProcessWindowStyle.Normal; public TilePanelContainer PanelContainer { get { if (this.Parent == null) { return null; } if (this.Parent.GetType() != typeof(TilePanelContainer)) { return null; } return (TilePanelContainer)this.Parent; } } private void panel_MouseDown(object sender, MouseEventArgs e) { TilePanelContainer container = this.PanelContainer; if (container == null) { return; } if (e.Button != MouseButtons.Left) { return; } isDragging = true; startPosition = e.Location; } private void panel_MouseUp(object sender, MouseEventArgs e) { isDragging = false; } private void panel_MouseMove(object sender, MouseEventArgs e) { if (isDragging) { TilePanelContainer container = this.PanelContainer; if (container == null) { return; } //label1.Text = e.Location.ToString(); //this.Location = new Point(e.Location.X - windowOffset.X, e.Location.Y - windowOffset.Y); //int x = parentPosition.X + (e.Location.X - positionOffset.X); //int y = parentPosition.Y + (e.Location.Y - positionOffset.Y); //this.Location = new Point(x, y); //int x = (tilePosition.X + e.Location.X); //int y = (tilePosition.Y + e.Location.Y); int x = (this.Location.X + (e.Location.X - startPosition.X)); int y = (this.Location.Y + (e.Location.Y - startPosition.Y)); this.Location = container.GetTilePosition(x, y); //label1.Text = x.ToString() + ", " + y.ToString(); //label1.Text = e.X.ToString() + ", " + e.Y.ToString(); //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); } } } }