aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/WinformsDesktop.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.WinForms/WinformsDesktop.cs')
-rw-r--r--ShiftOS.WinForms/WinformsDesktop.cs46
1 files changed, 46 insertions, 0 deletions
diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs
index 3050cdf..ee0f34d 100644
--- a/ShiftOS.WinForms/WinformsDesktop.cs
+++ b/ShiftOS.WinForms/WinformsDesktop.cs
@@ -452,7 +452,11 @@ namespace ShiftOS.WinForms
foreach(var widget in WidgetManager.GetAllWidgetTypes())
{
UserControl w = (UserControl)Activator.CreateInstance(widget.Value, null);
+
+ w.Location = WidgetManager.LoadLocation(w.GetType());
+
pnlwidgetlayer.Controls.Add(w);
+ MakeWidgetMovable(w);
Widgets.Add(w as IDesktopWidget);
}
}
@@ -481,6 +485,48 @@ namespace ShiftOS.WinForms
PopulatePanelButtons();
}
+ public void MakeWidgetMovable(Control w, Control startCtrl = null)
+ {
+ if (startCtrl == null)
+ startCtrl = w;
+
+ bool moving = false;
+
+ w.MouseDown += (o, a) =>
+ {
+ moving = true;
+ };
+
+ w.MouseMove += (o, a) =>
+ {
+ if (moving == true)
+ {
+ var mPos = Cursor.Position;
+ int mY = mPos.Y - desktoppanel.Height;
+ int mX = mPos.X;
+
+ int ctrlHeight = startCtrl.Height / 2;
+ int ctrlWidth = startCtrl.Width / 2;
+
+ startCtrl.Location = new Point(
+ mX - ctrlWidth,
+ mY - ctrlHeight
+ );
+
+ }
+ };
+
+ w.MouseUp += (o, a) =>
+ {
+ moving = false;
+ WidgetManager.SaveLocation(startCtrl.GetType(), w.Location);
+ };
+
+ foreach (Control c in w.Controls)
+ MakeWidgetMovable(c, startCtrl);
+
+ }
+
public ToolStripMenuItem GetALCategoryWithName(string text)
{
foreach (ToolStripMenuItem menuitem in apps.DropDownItems)