Changed: simplified tile container uc

This commit is contained in:
Ray 2020-05-15 23:34:31 +01:00
parent 9e167916cb
commit 19ea78868b
13 changed files with 1256 additions and 190 deletions

View File

@ -82,6 +82,7 @@
<Compile Include="RyzStudio\Windows\Forms\THorizontalSeparator.Designer.cs"> <Compile Include="RyzStudio\Windows\Forms\THorizontalSeparator.Designer.cs">
<DependentUpon>THorizontalSeparator.cs</DependentUpon> <DependentUpon>THorizontalSeparator.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="RyzStudio\Windows\Forms\ThreadControl.cs" />
<Compile Include="RyzStudio\Windows\Forms\TImageBox.cs"> <Compile Include="RyzStudio\Windows\Forms\TImageBox.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
@ -154,14 +155,11 @@
<Compile Include="Windows\Forms\AUserControl.cs"> <Compile Include="Windows\Forms\AUserControl.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
<Compile Include="Windows\Forms\Tile\TileLayoutContainer.cs"> <Compile Include="Windows\Forms\Tile\TilePanelLayout.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
<Compile Include="Windows\Forms\Tile\TileLayoutContainer.Designer.cs"> <Compile Include="Windows\Forms\Tile\TilePanelLayout.Designer.cs">
<DependentUpon>TileLayoutContainer.cs</DependentUpon> <DependentUpon>TilePanelLayout.cs</DependentUpon>
</Compile>
<Compile Include="Windows\Forms\Tile\TileLayoutPanel.cs">
<SubType>UserControl</SubType>
</Compile> </Compile>
<Compile Include="Windows\Forms\Tile\TilePanel.cs"> <Compile Include="Windows\Forms\Tile\TilePanel.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
@ -213,11 +211,8 @@
<EmbeddedResource Include="Windows\Forms\Tile\EditTileForm.resx"> <EmbeddedResource Include="Windows\Forms\Tile\EditTileForm.resx">
<DependentUpon>EditTileForm.cs</DependentUpon> <DependentUpon>EditTileForm.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Windows\Forms\Tile\TileLayoutContainer.resx"> <EmbeddedResource Include="Windows\Forms\Tile\TilePanelLayout.resx">
<DependentUpon>TileLayoutContainer.cs</DependentUpon> <DependentUpon>TilePanelLayout.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Windows\Forms\Tile\TileLayoutPanel.resx">
<DependentUpon>TileLayoutPanel.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Windows\Forms\Tile\TilePanel.resx"> <EmbeddedResource Include="Windows\Forms\Tile\TilePanel.resx">
<DependentUpon>TilePanel.cs</DependentUpon> <DependentUpon>TilePanel.cs</DependentUpon>

View File

@ -1,6 +1,7 @@
using AppLauncher.Models; using AppLauncher.Models;
using AppLauncher.Windows.Forms; using AppLauncher.Windows.Forms;
using Newtonsoft.Json; using Newtonsoft.Json;
using RyzStudio.Windows.Forms;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
@ -91,12 +92,12 @@ namespace AppLauncher
List<TileGroupModel> rs = new List<TileGroupModel>(); List<TileGroupModel> rs = new List<TileGroupModel>();
for (int i = 0; i < flowLayoutPanel1.Controls.Count; i++) for (int i = 0; i < flowLayoutPanel1.Controls.Count; i++)
{ {
if (flowLayoutPanel1.Controls[i].GetType() != typeof(TileLayoutContainer)) if (flowLayoutPanel1.Controls[i].GetType() != typeof(TilePanelLayout))
{ {
continue; continue;
} }
TileLayoutContainer container = flowLayoutPanel1.Controls[i] as TileLayoutContainer; TilePanelLayout container = flowLayoutPanel1.Controls[i] as TilePanelLayout;
rs.Add(container.Model); rs.Add(container.Model);
} }
@ -131,19 +132,12 @@ namespace AppLauncher
{ {
while (this.Width > width) while (this.Width > width)
{ {
if (this.InvokeRequired) ThreadControl.SetWidth(this, (this.Width - increment));
{
this.Invoke(new MethodInvoker(() => {
this.Width -= increment;
}));
}
else
{
this.Width -= increment;
}
Application.DoEvents(); Application.DoEvents();
} }
ThreadControl.SetWidth(this, width);
}); });
} }
@ -153,21 +147,12 @@ namespace AppLauncher
{ {
while (this.Width < width) while (this.Width < width)
{ {
if (this.InvokeRequired) ThreadControl.SetWidth(this, (this.Width + increment));
{
this.Invoke(new MethodInvoker(() => {
this.Width += increment;
//this.Invalidate();
}));
}
else
{
this.Width += increment;
//this.Invalidate();
}
Application.DoEvents(); Application.DoEvents();
} }
ThreadControl.SetWidth(this, width);
}); });
} }
@ -190,7 +175,7 @@ namespace AppLauncher
foreach (TileGroupModel item in rs) foreach (TileGroupModel item in rs)
{ {
TileLayoutContainer panel = new TileLayoutContainer(item); TilePanelLayout panel = new TilePanelLayout(item);
maxWidth = Math.Max(maxWidth, panel.Width); maxWidth = Math.Max(maxWidth, panel.Width);
flowLayoutPanel1.Controls.Add(panel); flowLayoutPanel1.Controls.Add(panel);

View File

@ -1,17 +1,11 @@
using System; using System.Drawing;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace RyzStudio.Windows.Forms namespace RyzStudio.Windows.Forms
{ {
public class TFlatButton : Label public class TFlatButton : Label
{ {
public class FlatButtonStyle public class ButtonStyle
{ {
public Color BackColour { get; set; } = Color.Transparent; public Color BackColour { get; set; } = Color.Transparent;
public Color PenColour { get; set; } = Color.Transparent; public Color PenColour { get; set; } = Color.Transparent;
@ -33,17 +27,17 @@ namespace RyzStudio.Windows.Forms
this.TextAlign = ContentAlignment.MiddleCenter; this.TextAlign = ContentAlignment.MiddleCenter;
// customise // customise
this.StyleOver = new FlatButtonStyle() this.StyleOver = new ButtonStyle()
{ {
BackColour = Color.FromArgb(51, 51, 51), BackColour = Color.FromArgb(51, 51, 51),
PenColour = Color.White PenColour = Color.White
}; };
this.StyleDown = new FlatButtonStyle() this.StyleDown = new ButtonStyle()
{ {
BackColour = Color.FromArgb(179, 179, 179), BackColour = Color.FromArgb(179, 179, 179),
PenColour = Color.Black PenColour = Color.Black
}; };
this.StyleDefault = new FlatButtonStyle() this.StyleDefault = new ButtonStyle()
{ {
BackColour = Color.White, BackColour = Color.White,
PenColour = Color.Black PenColour = Color.Black
@ -91,20 +85,17 @@ namespace RyzStudio.Windows.Forms
} }
} }
protected void updateButton(FlatButtonStyle style) protected void updateButton(ButtonStyle style)
{ {
this.ForeColor = style.PenColour; this.ForeColor = style.PenColour;
this.BackColor = style.BackColour; this.BackColor = style.BackColour;
} }
[Browsable(false)] protected ButtonStyle StyleOver { get; set; } = new ButtonStyle();
public FlatButtonStyle StyleOver { get; set; } = new FlatButtonStyle();
[Browsable(false)] protected ButtonStyle StyleDown { get; set; } = new ButtonStyle();
public FlatButtonStyle StyleDown { get; set; } = new FlatButtonStyle();
[Browsable(false)] protected ButtonStyle StyleDefault { get; set; } = new ButtonStyle();
public FlatButtonStyle StyleDefault { get; set; } = new FlatButtonStyle();
public void PerformClick() public void PerformClick()
{ {

View File

@ -0,0 +1,152 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RyzStudio.Windows.Forms
{
public class ThreadControl
{
public static void AddControl(Control control, Control value)
{
if (control.InvokeRequired)
{
control.Invoke(new MethodInvoker(() =>
{
control.Controls.Add(value);
}));
}
else
{
control.Controls.Add(value);
}
}
public static void AddItem(ListBox control, string value)
{
if (control.InvokeRequired)
{
control.Invoke(new MethodInvoker(() => {
control.Items.Add(value);
}));
}
else
{
control.Items.Add(value);
}
}
public static void Clear(ListBox control)
{
if (control.InvokeRequired)
{
control.Invoke(new MethodInvoker(() => {
control.Items.Clear();
}));
}
else
{
control.Items.Clear();
}
}
public static string GetText(Control control, bool doTrim = true)
{
string rv = string.Empty;
if (control.InvokeRequired)
{
control.Invoke(new MethodInvoker(() => {
rv = (doTrim ? control.Text?.Trim() : control.Text);
}));
}
else
{
rv = (doTrim ? control.Text?.Trim() : control.Text);
}
return rv;
}
public static int GetValue(NumericUpDown sender)
{
int rv = 0;
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => {
rv = (int)sender.Value;
}));
}
else
{
rv = (int)sender.Value;
}
return rv;
}
public string GetSelectedValue(ListBox sender)
{
string rv = string.Empty;
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => {
rv = (sender.SelectedItem == null) ? string.Empty : sender.SelectedItem.ToString();
}));
}
else
{
rv = (sender.SelectedItem == null) ? string.Empty : sender.SelectedItem.ToString();
}
return rv;
}
public static void SetHeight(Control control, int value)
{
if (control.InvokeRequired)
{
control.Invoke(new MethodInvoker(() => {
control.Height = value;
}));
}
else
{
control.Height = value;
}
}
public static void SetValue(Control control, string value)
{
if (control.InvokeRequired)
{
control.Invoke(new MethodInvoker(() => {
control.Text = value;
}));
}
else
{
control.Text = value;
}
}
public static void SetWidth(Control control, int value)
{
if (control.InvokeRequired)
{
control.Invoke(new MethodInvoker(() => {
control.Width = value;
}));
}
else
{
control.Width = value;
}
}
}
}

View File

@ -108,117 +108,6 @@
this.Close(); this.Close();
} }
public void SetValue(Label sender, string value)
{
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { sender.Text = value; }));
}
else
{
sender.Text = value;
}
}
public void SetValue(GroupBox sender, string value)
{
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { sender.Text = value; }));
}
else
{
sender.Text = value;
}
}
public void AddValue(ListBox sender, string value)
{
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { sender.Items.Add(value); }));
}
else
{
sender.Items.Add(value);
}
}
public void AddControl(FlowLayoutPanel sender, Control value)
{
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() =>
{
sender.Controls.Add(value);
}));
}
else
{
sender.Controls.Add(value);
}
}
public void ClearValues(ListBox sender)
{
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { sender.Items.Clear(); }));
}
else
{
sender.Items.Clear();
}
}
public string GetValue(ListBox sender)
{
string rv = string.Empty;
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { rv = (sender.SelectedItem == null) ? string.Empty : sender.SelectedItem.ToString(); }));
}
else
{
rv = (sender.SelectedItem == null) ? string.Empty : sender.SelectedItem.ToString();
}
return rv;
}
public string GetValue(TTextBox sender)
{
string rv = string.Empty;
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { rv = sender.Text.Trim(); }));
}
else
{
rv = sender.Text.Trim();
}
return rv;
}
public int GetValue(NumericUpDown sender)
{
int rv = 0;
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { rv = (int)sender.Value; }));
}
else
{
rv = (int)sender.Value;
}
return rv;
}
private void label1_MouseDown(object sender, MouseEventArgs e) private void label1_MouseDown(object sender, MouseEventArgs e)
{ {
if (e.Button != MouseButtons.Left) if (e.Button != MouseButtons.Left)

View File

@ -102,17 +102,5 @@ namespace RyzStudio.Windows.ThemedForms
} }
} }
public void SetValue(Label sender, string value)
{
if (sender.InvokeRequired)
{
sender.Invoke(new MethodInvoker(() => { sender.Text = value; }));
}
else
{
sender.Text = value;
}
}
} }
} }

View File

@ -6,7 +6,7 @@ namespace AppLauncher.Windows.Forms
{ {
public class AddListTileForm : TDialogForm public class AddListTileForm : TDialogForm
{ {
public static void ShowDialog(TileLayoutPanel panel) public static void ShowDialog(TilePanelLayout panel)
{ {
AddListTileForm form = new AddListTileForm(panel); AddListTileForm form = new AddListTileForm(panel);
form.ShowDialog(); form.ShowDialog();
@ -16,14 +16,14 @@ namespace AppLauncher.Windows.Forms
private TButton button1; private TButton button1;
private RyzStudio.Windows.Forms.THorizontalSeparator horizontalSeparator1; private RyzStudio.Windows.Forms.THorizontalSeparator horizontalSeparator1;
private TTextBox textBox1; private TTextBox textBox1;
protected TileLayoutPanel parentPanel = null; protected TilePanelLayout parentPanel = null;
public AddListTileForm() : base() public AddListTileForm() : base()
{ {
InitializeComponent(); InitializeComponent();
} }
public AddListTileForm(TileLayoutPanel panel) : base() public AddListTileForm(TilePanelLayout panel) : base()
{ {
parentPanel = panel; parentPanel = panel;

View File

@ -11,7 +11,7 @@ namespace AppLauncher.Windows.Forms
{ {
public class AddTileForm : TDialogForm public class AddTileForm : TDialogForm
{ {
public static void ShowDialog(TileLayoutPanel panel) public static void ShowDialog(TilePanelLayout panel)
{ {
AddTileForm form = new AddTileForm(panel); AddTileForm form = new AddTileForm(panel);
form.ShowDialog(); form.ShowDialog();
@ -32,7 +32,7 @@ namespace AppLauncher.Windows.Forms
private RyzStudio.Windows.Forms.THorizontalSeparator horizontalSeparator1; private RyzStudio.Windows.Forms.THorizontalSeparator horizontalSeparator1;
private RyzStudio.Windows.Forms.THorizontalSeparator horizontalSeparator2; private RyzStudio.Windows.Forms.THorizontalSeparator horizontalSeparator2;
private TTextBox textBox1; private TTextBox textBox1;
protected TileLayoutPanel parentPanel = null; protected TilePanelLayout parentPanel = null;
public AddTileForm() : base() public AddTileForm() : base()
{ {
@ -40,7 +40,7 @@ namespace AppLauncher.Windows.Forms
initialiseComponents2(); initialiseComponents2();
} }
public AddTileForm(TileLayoutPanel panel) : base() public AddTileForm(TilePanelLayout panel) : base()
{ {
parentPanel = panel; parentPanel = panel;

View File

@ -11,7 +11,7 @@ namespace AppLauncher.Windows.Forms
private TButton button1; private TButton button1;
private TPickerBox pickerBox1; private TPickerBox pickerBox1;
private TTextBox textBox1; private TTextBox textBox1;
protected TileLayoutContainer parentContainer = null; protected TilePanelLayout parentContainer = null;
public EditGroupForm() : base() public EditGroupForm() : base()
{ {
@ -19,7 +19,7 @@ namespace AppLauncher.Windows.Forms
initialiseComponents2(); initialiseComponents2();
} }
public EditGroupForm(TileLayoutContainer container) : base() public EditGroupForm(TilePanelLayout container) : base()
{ {
parentContainer = container; parentContainer = container;

View File

@ -41,7 +41,7 @@ namespace AppLauncher.Windows.Forms
[Browsable(false)] [Browsable(false)]
public TileModel ModelInfo => modelInfo; public TileModel ModelInfo => modelInfo;
public TileLayoutPanel PanelContainer public TilePanelLayout PanelContainer
{ {
get get
{ {
@ -50,12 +50,12 @@ namespace AppLauncher.Windows.Forms
return null; return null;
} }
if (this.Parent.GetType() != typeof(TileLayoutPanel)) if (this.Parent.GetType() != typeof(TilePanelLayout))
{ {
return null; return null;
} }
return (TileLayoutPanel)this.Parent; return (TilePanelLayout)this.Parent;
} }
} }
@ -96,7 +96,7 @@ namespace AppLauncher.Windows.Forms
private void panel_MouseDown(object sender, MouseEventArgs e) private void panel_MouseDown(object sender, MouseEventArgs e)
{ {
TileLayoutPanel container = this.PanelContainer; TilePanelLayout container = this.PanelContainer;
if (container == null) if (container == null)
{ {
return; return;
@ -122,7 +122,7 @@ namespace AppLauncher.Windows.Forms
{ {
if (isDragging) if (isDragging)
{ {
TileLayoutPanel layoutPanel = this.PanelContainer; TilePanelLayout layoutPanel = this.PanelContainer;
if (layoutPanel == null) if (layoutPanel == null)
{ {
return; return;

View File

@ -0,0 +1,193 @@
namespace AppLauncher.Windows.Forms
{
partial class TilePanelLayout
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.addToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.addListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStrip2 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem5 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem();
this.topToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.upToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.downToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bottomToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStrip1.SuspendLayout();
this.contextMenuStrip2.SuspendLayout();
this.SuspendLayout();
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.addToolStripMenuItem,
this.addListToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(181, 70);
//
// addToolStripMenuItem
//
this.addToolStripMenuItem.Name = "addToolStripMenuItem";
this.addToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.addToolStripMenuItem.Text = "&Add Tile";
this.addToolStripMenuItem.Click += new System.EventHandler(this.addTileMenuItem_Click);
//
// addListToolStripMenuItem
//
this.addListToolStripMenuItem.Name = "addListToolStripMenuItem";
this.addListToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.addListToolStripMenuItem.Text = "Add &List Tile";
this.addListToolStripMenuItem.Click += new System.EventHandler(this.addListTileMenuItem_Click);
//
// contextMenuStrip2
//
this.contextMenuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItem2,
this.toolStripMenuItem5,
this.toolStripMenuItem1,
this.toolStripSeparator2,
this.toolStripMenuItem4,
this.toolStripSeparator1,
this.toolStripMenuItem3});
this.contextMenuStrip2.Name = "contextMenuStrip1";
this.contextMenuStrip2.Size = new System.Drawing.Size(133, 126);
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(132, 22);
this.toolStripMenuItem2.Text = "&Add Group";
this.toolStripMenuItem2.Click += new System.EventHandler(this.addGroupMenuItem_Click);
//
// toolStripMenuItem5
//
this.toolStripMenuItem5.Name = "toolStripMenuItem5";
this.toolStripMenuItem5.Size = new System.Drawing.Size(132, 22);
this.toolStripMenuItem5.Text = "Add &Row";
this.toolStripMenuItem5.Click += new System.EventHandler(this.addRowMenuItem_Click);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(132, 22);
this.toolStripMenuItem1.Text = "&Edit";
this.toolStripMenuItem1.Click += new System.EventHandler(this.editGroupMenuItem_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(129, 6);
//
// toolStripMenuItem4
//
this.toolStripMenuItem4.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.topToolStripMenuItem,
this.upToolStripMenuItem,
this.downToolStripMenuItem,
this.bottomToolStripMenuItem});
this.toolStripMenuItem4.Name = "toolStripMenuItem4";
this.toolStripMenuItem4.Size = new System.Drawing.Size(132, 22);
this.toolStripMenuItem4.Text = "&Move";
//
// topToolStripMenuItem
//
this.topToolStripMenuItem.Name = "topToolStripMenuItem";
this.topToolStripMenuItem.Size = new System.Drawing.Size(114, 22);
this.topToolStripMenuItem.Text = "&Top";
this.topToolStripMenuItem.Click += new System.EventHandler(this.moveTopMenuItem_Click);
//
// upToolStripMenuItem
//
this.upToolStripMenuItem.Name = "upToolStripMenuItem";
this.upToolStripMenuItem.Size = new System.Drawing.Size(114, 22);
this.upToolStripMenuItem.Text = "&Up";
this.upToolStripMenuItem.Click += new System.EventHandler(this.moveUpMenuItem_Click);
//
// downToolStripMenuItem
//
this.downToolStripMenuItem.Name = "downToolStripMenuItem";
this.downToolStripMenuItem.Size = new System.Drawing.Size(114, 22);
this.downToolStripMenuItem.Text = "&Down";
this.downToolStripMenuItem.Click += new System.EventHandler(this.moveDownMenuItem_Click);
//
// bottomToolStripMenuItem
//
this.bottomToolStripMenuItem.Name = "bottomToolStripMenuItem";
this.bottomToolStripMenuItem.Size = new System.Drawing.Size(114, 22);
this.bottomToolStripMenuItem.Text = "&Bottom";
this.bottomToolStripMenuItem.Click += new System.EventHandler(this.moveBottomMenuItem_Click);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(129, 6);
//
// toolStripMenuItem3
//
this.toolStripMenuItem3.Name = "toolStripMenuItem3";
this.toolStripMenuItem3.Size = new System.Drawing.Size(132, 22);
this.toolStripMenuItem3.Text = "&Remove";
this.toolStripMenuItem3.Click += new System.EventHandler(this.removeGroupMenuItem3_Click);
//
// TilePanelLayout
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Transparent;
this.Name = "TilePanelLayout";
this.Size = new System.Drawing.Size(370, 150);
this.contextMenuStrip1.ResumeLayout(false);
this.contextMenuStrip2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem addToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem addListToolStripMenuItem;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip2;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem5;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem4;
private System.Windows.Forms.ToolStripMenuItem topToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem upToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem downToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem bottomToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem3;
}
}

View File

@ -0,0 +1,747 @@
using AppLauncher.Models;
using RyzStudio.Windows.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AppLauncher.Windows.Forms
{
public partial class TilePanelLayout : AUserControl
{
public class Item
{
public TilePanel Tile { get; set; }
public Point Coord { get; set; } = new Point(0, 0);
}
protected readonly int tileSize = 70;
protected readonly int margin = 3;
protected readonly int labelHeight = 20;
protected readonly int collapseIncrement = 6;
protected readonly int expandIncrement = 8;
protected TileGroupModel groupInfo = null;
protected List<Item> items = new List<Item>();
protected int collapseHeight = 0;
protected int expandedHeight = 0;
protected bool isAnimating = false;
protected bool isChecked = true;
public TilePanelLayout(TileGroupModel model) : base()
{
InitializeComponent();
this.AllowDrop = true;
this.BackColor = Color.Transparent;
this.LoadModel(model);
//panel1.Resize += panel1_Resize;
}
protected override void OnDragDrop(DragEventArgs e)
{
string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
if (fileList == null)
{
return;
}
if (fileList.Length <= 0)
{
return;
}
if (string.IsNullOrWhiteSpace(fileList[0]))
{
return;
}
TileModel model = new TileModel()
{
ProcessFilename = fileList[0],
Title = Path.GetFileName(fileList[0])
};
// exe
if (Path.GetExtension(fileList[0]).Equals(".exe", StringComparison.CurrentCultureIgnoreCase))
{
if (File.Exists(fileList[0]))
{
try
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(fileList[0]);
if (fvi != null)
{
model.Title = fvi.ProductName;
}
}
catch
{
// do nothing
}
}
}
this.AddTile(model);
}
protected override void OnDragOver(DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Link;
}
else
{
e.Effect = DragDropEffects.None;
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.Margin = new Padding(0);
this.Padding = new Padding(0, 0, 0, 10);
//this.MaximumSize = new Size(panel1.Width, ExpandedHeight);
//this.MinimumSize = new Size(panel1.Width, label1.Height);
//this.Size = this.MaximumSize;
//this.Size = new Size(panel1.Width, this.ExpandedHeight);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawImageUnscaled((isChecked ? Properties.Resources.toggle_right_ea_16 : Properties.Resources.toggle_left_ea_16), 2, 2);
TextRenderer.DrawText(g, groupInfo?.Title, new Font(this.Font.FontFamily, 8.25F), new Point(25, 4), Color.FromArgb(99, 105, 119));
}
protected override async void OnResize(EventArgs e)
{
base.OnResize(e);
await this.InvalidateContainer();
}
protected override async void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
bool isLabel = ((e.Location.X >= 0) && (e.Location.X <= this.Width) && (e.Location.Y >= 0) && (e.Location.Y <= 20));
if (e.Button == MouseButtons.Left)
{
if (isLabel)
{
isChecked = !isChecked;
this.Invalidate();
await this.InvalidateContainer();
}
else
{
}
}
else if (e.Button == MouseButtons.Right)
{
if (isLabel)
{
contextMenuStrip2.Show(this, e.Location);
}
else
{
contextMenuStrip1.Show(this, e.Location);
}
}
}
protected override void OnMouseDoubleClick(MouseEventArgs e) => base.OnMouseClick(e);
//private async void panel1_Resize(object sender, EventArgs e) => await this.InvalidateContainer();
public Point GridSize
{
get
{
int w = (int)Math.Floor(decimal.Divide(this.Width, this.TileSize));
int h = (int)Math.Floor(decimal.Divide(this.Height - labelHeight, this.TileSize));
return new Point(w, h);
}
}
public int CollapseHeight => labelHeight + collapseHeight;
public int ExpandedHeight => expandedHeight + this.Padding.Bottom;
//public int CollapseHeight => labelHeight + collapseHeight panel1.CollapseHeight;
//public int ExpandedHeight => labelHeight + panel1.ExpandedHeight + this.Padding.Top + this.Padding.Bottom;
public TileGroupModel Model
{
get
{
TileGroupModel rs = new TileGroupModel()
{
Title = groupInfo.Title,
//GridSize = new Size(panel1.GridSize.X, panel1.GridSize.Y),
GridSize = new Size(this.GridSize.X, this.GridSize.Y),
IsExpanded = isChecked,
IsExclusive = groupInfo.IsExclusive,
Items = this.Tiles
//Items = panel1.Tiles
};
return rs;
}
}
public FlowLayoutPanel FlowLayoutPanel
{
get
{
if (this.Parent == null)
{
return null;
}
if (this.Parent.GetType() != typeof(FlowLayoutPanel))
{
return null;
}
return this.Parent as FlowLayoutPanel;
}
}
public List<TileModel> Tiles
{
get
{
List<TileModel> rs = new List<TileModel>();
foreach (Item item in items)
{
TileModel model = item.Tile.ModelInfo;
model.Position = item.Coord;
rs.Add(model);
}
return rs;
}
}
public int TileSize => (tileSize + margin);
public void AddTile(TileModel tile)
{
Point gridSize = this.GridSize;
if (items.Count >= (gridSize.X * gridSize.Y))
{
this.SetGridSize(gridSize.X, (gridSize.Y + 1));
}
Point? newCoord = findLastFreeCoord();
if (newCoord == null)
{
return;
}
tile.Position = newCoord.Value;
TilePanel panel = new TilePanel();
panel.LoadInfo(tile);
panel.Location = convertCoordToLocation(tile.Position);
items.Add(new Item()
{
Tile = panel,
Coord = tile.Position
});
this.Controls.Add(panel);
}
public void Clear()
{
this.Controls.Clear();
}
public async Task Collapse()
{
await Task.Run(() =>
{
if (isAnimating) return;
isAnimating = true;
while (this.Height > this.CollapseHeight)
{
ThreadControl.SetHeight(this, (this.Height - collapseIncrement));
Thread.Sleep(10);
}
ThreadControl.SetHeight(this, this.CollapseHeight);
isAnimating = false;
});
}
public async Task CollapseNow()
{
await Task.Run(() =>
{
if (isAnimating) return;
isAnimating = true;
ThreadControl.SetHeight(this, this.CollapseHeight);
isAnimating = false;
});
}
public async Task Expand()
{
await Task.Run(() =>
{
if (isAnimating) return;
isAnimating = true;
while (this.Height < this.ExpandedHeight)
{
ThreadControl.SetHeight(this, (this.Height + expandIncrement));
this.Invalidate();
Thread.Sleep(10);
}
ThreadControl.SetHeight(this, this.ExpandedHeight);
isAnimating = false;
});
}
public Point GetTilePosition(int posX, int posY)
{
int x = (int)Math.Round(decimal.Divide(posX, this.TileSize));
int y = (int)Math.Round(decimal.Divide((posY - labelHeight), this.TileSize));
if (x < 0) x = 0;
if (y < 0) y = 0;
return new Point((x * this.TileSize), ((y * this.TileSize) + labelHeight));
}
public async Task InvalidateContainer(bool animate = true)
{
if (isAnimating)
{
return;
}
if (isChecked)
{
await this.Expand();
}
else
{
if (animate)
{
await this.Collapse();
}
else
{
await this.CollapseNow();
}
}
}
public void AddGroup()
{
if (this.FlowLayoutPanel == null)
{
return;
}
this.FlowLayoutPanel.Controls.Add(new TilePanelLayout(new TileGroupModel()
{
Title = "New Group",
GridSize = new Size(8, 1)
}));
}
public void AddRow()
{
//panel1.SetGridSize(groupInfo.GridSize.Width, (groupInfo.GridSize.Height + 1));
this.SetGridSize(groupInfo.GridSize.Width, (groupInfo.GridSize.Height + 1));
}
public void EditGroup()
{
//EditGroupForm editForm = new EditGroupForm(this);
//editForm.ShowDialog();
}
public void LoadModel(TileGroupModel model, bool loadTiles = true)
{
groupInfo = model;
this.SetGridSize(groupInfo.GridSize.Width, groupInfo.GridSize.Height);
//this.Width = panel1.Width;
isChecked = groupInfo.IsExpanded;
if (loadTiles)
{
this.LoadTiles(model.Items);
}
this.Invalidate();
}
public void LoadTiles(List<TileModel> tiles)
{
if (tiles == null)
{
return;
}
if (tiles.Count() <= 0)
{
return;
}
foreach (TileModel item in tiles)
{
// resolve final grid position
Point? confirmedPosition = resolveCoord(item.Position);
if (confirmedPosition == null)
{
continue;
}
// place control
TilePanel panel = new TilePanel();
panel.LoadInfo(item);
panel.Location = convertCoordToLocation(confirmedPosition.Value);
items.Add(new Item()
{
Tile = panel,
Coord = confirmedPosition.Value
});
this.Controls.Add(panel);
}
}
public void MoveTile(TilePanel panel, int posX, int posY)
{
Item item = items.Where(x => x.Tile.Equals(panel)).FirstOrDefault();
if (item == null)
{
return;
}
Point newPosition = convertLocationToCoord(posX, posY);
if (!isTileInBounds(newPosition))
{
return;
}
if (hasTile(newPosition))
{
Item swapItem = items.Where(x => x.Coord.Equals(newPosition)).FirstOrDefault();
if (swapItem != null)
{
swapItem.Coord = item.Coord;
swapItem.Tile.Location = convertCoordToLocation(item.Coord);
}
item.Coord = newPosition;
panel.Location = convertCoordToLocation(newPosition);
}
else
{
item.Coord = newPosition;
panel.Location = convertCoordToLocation(newPosition);
}
}
public void MoveTop()
{
if (this.FlowLayoutPanel == null)
{
return;
}
this.FlowLayoutPanel.Controls.SetChildIndex(this, 0);
}
public void MoveUp()
{
if (this.FlowLayoutPanel == null)
{
return;
}
int pos = this.FlowLayoutPanel.Controls.GetChildIndex(this);
if (pos <= 0)
{
return;
}
this.FlowLayoutPanel.Controls.SetChildIndex(this, (pos - 1));
}
public void MoveDown()
{
if (this.FlowLayoutPanel == null)
{
return;
}
int pos = this.FlowLayoutPanel.Controls.GetChildIndex(this);
if (pos >= (this.FlowLayoutPanel.Controls.Count - 1))
{
return;
}
this.FlowLayoutPanel.Controls.SetChildIndex(this, (pos + 1));
}
public void MoveBottom()
{
if (this.FlowLayoutPanel == null)
{
return;
}
this.FlowLayoutPanel.Controls.SetChildIndex(this, (this.FlowLayoutPanel.Controls.Count - 1));
}
public void Remove()
{
if (this.FlowLayoutPanel == null)
{
return;
}
this.FlowLayoutPanel.Controls.Remove(this);
}
public void Remove(TilePanel panel)
{
Item m = items.Where(x => x.Tile.Equals(panel)).FirstOrDefault();
if (m != null)
{
items.Remove(m);
}
this.Controls.Remove(panel);
}
public void SetGridSize(int width, int height)
{
expandedHeight = (this.TileSize * height) + labelHeight;
this.Size = new Size((this.TileSize * width), expandedHeight);
}
protected Point convertCoordToLocation(Point position) => new Point((position.X * this.TileSize), ((position.Y * this.TileSize) + labelHeight));
protected Point convertLocationToCoord(int posX, int posY)
{
int x = (int)Math.Round(decimal.Divide(posX, this.TileSize));
int y = (int)Math.Round(decimal.Divide((posY - labelHeight), this.TileSize));
if (x < 0) x = 0;
if (y < 0) y = 0;
return new Point(x, y);
}
protected Point? findFirstFreeCoord()
{
Point gridSize = this.GridSize;
for (int y = 0; y < gridSize.Y; y++)
{
for (int x = 0; x < gridSize.X; x++)
{
if (hasTile(new Point(x, y)))
{
continue;
}
return new Point(x, y);
}
}
return null;
}
protected Point? findLastFreeCoord()
{
Point gridSize = this.GridSize;
// none available
if (items.Count >= (gridSize.X * gridSize.Y))
{
return null;
}
if (items.Count <= 0)
{
return findFirstFreeCoord();
}
// only one available
if (items.Count >= ((gridSize.X * gridSize.Y) - 1))
{
return findFirstFreeCoord();
}
Point? rv = null;
for (int y = (gridSize.Y - 1); y >= 0; y--)
{
for (int x = (gridSize.X - 1); x >= 0; x--)
{
if (hasTile(new Point(x, y)))
{
if (rv.HasValue)
{
return rv;
}
}
else
{
rv = new Point(x, y);
}
}
}
return null;
}
protected bool hasTile(Point position)
{
if (items == null)
{
return false;
}
if (items.Count <= 0)
{
return false;
}
return (items.Count(x => x.Coord.Equals(position)) > 0);
}
protected bool isTileInBounds(Point position)
{
Point gridSize = this.GridSize;
if (position.X >= gridSize.X)
{
return false;
}
if (position.Y >= gridSize.Y)
{
return false;
}
return true;
}
protected Point? resolveCoord(Point coord)
{
if (!isTileInBounds(coord))
{
return null;
}
if (!hasTile(coord))
{
return coord;
}
return resolveNextCoord(coord);
}
protected Point? resolveNextCoord(Point coord)
{
Point gridSize = this.GridSize;
Point newCoord = coord;
while (true)
{
newCoord.X++;
if (newCoord.X >= gridSize.X)
{
newCoord.Y++;
newCoord.X = 0;
}
if (!isTileInBounds(newCoord))
{
return null;
}
if (hasTile(newCoord))
{
continue;
}
return newCoord;
}
}
private void addTileMenuItem_Click(object sender, EventArgs e) => AddTileForm.ShowDialog(this);
private void addListTileMenuItem_Click(object sender, EventArgs e) => AddListTileForm.ShowDialog(this);
private void addGroupMenuItem_Click(object sender, EventArgs e) => this.AddGroup();
private void addRowMenuItem_Click(object sender, EventArgs e) => this.AddRow();
private void editGroupMenuItem_Click(object sender, EventArgs e) => this.EditGroup();
private void moveTopMenuItem_Click(object sender, EventArgs e) => this.MoveTop();
private void moveUpMenuItem_Click(object sender, EventArgs e) => this.MoveUp();
private void moveDownMenuItem_Click(object sender, EventArgs e) => this.MoveDown();
private void moveBottomMenuItem_Click(object sender, EventArgs e) => this.MoveBottom();
private void removeGroupMenuItem3_Click(object sender, EventArgs e) => this.Remove();
}
}

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="contextMenuStrip2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>172, 17</value>
</metadata>
</root>