WingMan

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 32  →  ?path2? @ 33
/trunk/WingMan/WingManForm.cs
@@ -24,6 +24,8 @@
{
public partial class WingManForm : Form
{
private const int tabControlDetachPixelOffset = 20;
 
public WingManForm()
{
InitializeComponent();
@@ -131,6 +133,10 @@
 
public KeySimulator KeySimulator { get; set; }
 
private static Point tabControlClickStartPosition { get; set; }
private static TabControl DetachedTabControl { get; set; }
private static Form DetachedForm { get; set; }
 
public void OnDiscoveryPortMapFailed(object sender, DiscoveryFailedEventArgs args)
{
switch (args.Type)
@@ -752,6 +758,88 @@
await SaveLocalMouseKeyBindings();
}
 
private void WingManTabControlMouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
 
tabControlClickStartPosition = e.Location;
}
 
private void WingManTabControlMouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
var mouseOffsetX = tabControlClickStartPosition.X - e.X;
var mouseOffsetY = tabControlClickStartPosition.Y - e.Y;
 
if (mouseOffsetX <= tabControlDetachPixelOffset && mouseOffsetY <= tabControlDetachPixelOffset)
return;
 
tabControl1.DoDragDrop(tabControl1.SelectedTab, DragDropEffects.Move);
tabControlClickStartPosition = new Point();
 
return;
}
 
tabControlClickStartPosition = new Point();
}
 
private void WingManTabControlGiveFeedback(object sender, GiveFeedbackEventArgs e)
{
e.UseDefaultCursors = false;
}
 
private void WingManTabControlQueryContinueDrag(object sender, QueryContinueDragEventArgs e)
{
if (MouseButtons != MouseButtons.Left)
{
e.Action = DragAction.Cancel;
 
DetachedForm = new Form
{
Size = new Size(
// Width = tab control width + tab control left and right margins + x-padding
tabControl1.Width +
tabControl1.Margin.Right +
tabControl1.Margin.Left +
tabControl1.Padding.X,
// Tab Height = tab control height - tab control tab page height
// Height = tab control height + Tab Height + top and bottom margin + x-padding
2 * tabControl1.Height -
tabControl1.SelectedTab.Height +
tabControl1.Margin.Top +
tabControl1.Margin.Bottom +
tabControl1.Padding.Y),
StartPosition = FormStartPosition.Manual,
Location = MousePosition,
MaximizeBox = false,
SizeGripStyle = SizeGripStyle.Hide,
FormBorderStyle = FormBorderStyle.FixedSingle
};
 
DetachedTabControl = new TabControl
{
Dock = DockStyle.Fill,
SizeMode = TabSizeMode.Fixed
};
DetachedTabControl.TabPages.Add(tabControl1.SelectedTab);
DetachedForm.Controls.Add(DetachedTabControl);
DetachedForm.FormClosing += DetachedFormOnFormClosing;
DetachedForm.Show();
Cursor = Cursors.Default;
return;
}
 
e.Action = DragAction.Continue;
Cursor = Cursors.SizeAll;
}
 
private void DetachedFormOnFormClosing(object sender, FormClosingEventArgs e)
{
tabControl1.TabPages.Insert(DetachedTabControl.SelectedTab.TabIndex, DetachedTabControl.SelectedTab);
DetachedForm.FormClosing -= DetachedFormOnFormClosing;
}
 
#region Saving and loading
 
private async Task SaveLocalMouseKeyBindings()