2020-04-11 17:43:20 +00:00
|
|
|
|
using AppLauncher.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace AppLauncher.Windows.Forms
|
|
|
|
|
{
|
|
|
|
|
public partial class TilePanel : AUserControl
|
|
|
|
|
{
|
|
|
|
|
protected bool isDragging = false;
|
|
|
|
|
protected Point startPosition = new Point();
|
|
|
|
|
|
|
|
|
|
protected TileModel model = new TileModel();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Category("Appearance"), Browsable(true)]
|
|
|
|
|
public string Title { get => label1.Text; protected set => label1.Text = value; }
|
|
|
|
|
|
|
|
|
|
[Category("Appearance"), Browsable(true)]
|
|
|
|
|
public Image Image { get => pictureBox1.BackgroundImage; protected set => pictureBox1.BackgroundImage = value; }
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public TileModel Info => model;
|
|
|
|
|
|
|
|
|
|
public TileLayoutPanel PanelContainer
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (this.Parent == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.Parent.GetType() != typeof(TileLayoutPanel))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (TileLayoutPanel)this.Parent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadInfo(TileModel model)
|
|
|
|
|
{
|
|
|
|
|
this.model = model;
|
|
|
|
|
|
|
|
|
|
this.Title = model.Title;
|
2020-04-12 00:12:21 +00:00
|
|
|
|
//this.Image = model.Icon;
|
|
|
|
|
|
|
|
|
|
//if (this.Image == null)
|
|
|
|
|
//{
|
|
|
|
|
// if (File.Exists(model.ProcessFilename))
|
|
|
|
|
// {
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// this.Image = Icon.ExtractAssociatedIcon(model.ProcessFilename)?.ToBitmap();
|
|
|
|
|
// }
|
|
|
|
|
// catch
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2020-04-11 17:43:20 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void panel_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
TileLayoutPanel container = this.PanelContainer;
|
|
|
|
|
if (container == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.Button != MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.BringToFront();
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
TileLayoutPanel layoutPanel = this.PanelContainer;
|
|
|
|
|
if (layoutPanel == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int x = (this.Location.X + (e.Location.X - startPosition.X));
|
|
|
|
|
int y = (this.Location.Y + (e.Location.Y - startPosition.Y));
|
|
|
|
|
|
|
|
|
|
layoutPanel.MoveTile(this, x, y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TilePanel_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.Info == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(this.Info.ProcessFilename))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(this.Info.ProcessFilename))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProcessStartInfo p = new ProcessStartInfo();
|
|
|
|
|
p.FileName = this.Info.ProcessFilename;
|
|
|
|
|
p.WindowStyle = this.Info.ProcessWindowStyle;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(this.Info.ProcessArgument)) p.Arguments = this.Info.ProcessArgument;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(this.Info.ProcessWorkingDirectory)) p.WorkingDirectory = this.Info.ProcessWorkingDirectory;
|
|
|
|
|
if (this.Info.ProcessAsAdmin) p.Verb = "runas";
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Process.Start(p);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TilePanel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// do nothing yet
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|