Skip to content
This repository was archived by the owner on Jun 23, 2021. It is now read-only.

Commit 56ee714

Browse files
committed
增加拖拽变更选项卡位置的功能
PS.以最low的方式实现的。。。
1 parent 2a7e34b commit 56ee714

File tree

5 files changed

+67
-46
lines changed

5 files changed

+67
-46
lines changed

RdpTest/App.config

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<configSections>
4-
5-
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
6-
</configSections>
73
<startup>
8-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
95
</startup>
10-
<entityFramework>
11-
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
12-
<parameters>
13-
<parameter value="v13.0" />
14-
</parameters>
15-
</defaultConnectionFactory>
16-
<providers>
17-
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
18-
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
19-
</providers>
20-
</entityFramework>
21-
22-
</configuration>
6+
</configuration>

RdpTest/MainForm.Designer.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RdpTest/MainForm.cs

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,58 @@ private void btnAddRemoteHost_Click(object sender, EventArgs e)
175175
#region 页签控制
176176
private void tabMain_MouseDown(object sender, MouseEventArgs e)
177177
{
178-
if (e.Button == MouseButtons.Right)
178+
var index = InTabPageHead(e.Location);
179+
if (index > 0)
179180
{
180-
for (int i = 1, count = tabMain.TabPages.Count; i < count; i++) //排除首页
181+
tabMain.SelectedIndex = index;
182+
183+
if (e.Button == MouseButtons.Right)
184+
tabMain.ContextMenuStrip = menuTabPage; //弹出菜单
185+
else
186+
_tabMoving = true;
187+
}
188+
}
189+
190+
/// <summary>
191+
/// 正在移动 TabPage 位置
192+
/// </summary>
193+
private bool _tabMoving;
194+
private void tabMain_MouseMove(object sender, MouseEventArgs e)
195+
{
196+
if (_tabMoving)
197+
{
198+
var index = InTabPageHead(e.Location);
199+
if (index > 0 && tabMain.SelectedIndex != index)
181200
{
182-
var tp = tabMain.TabPages[i];
183-
if (tabMain.GetTabRect(i).Contains(new Point(e.X, e.Y)))
184-
{
185-
tabMain.SelectedTab = tp;
186-
tabMain.ContextMenuStrip = menuTabPage; //弹出菜单
187-
break;
188-
}
201+
var currPage = tabMain.SelectedTab;
202+
203+
tabMain.TabPages.Remove(currPage);
204+
tabMain.TabPages.Insert(index, currPage);
205+
tabMain.SelectedTab = currPage;
189206
}
190207
}
191208
}
192209

210+
private int InTabPageHead(Point location)
211+
{
212+
for (int i = 1, count = tabMain.TabPages.Count; i < count; i++) //排除首页
213+
{
214+
var rect = tabMain.GetTabRect(i);
215+
var offset = rect.Width / 4;
216+
rect = new Rectangle(rect.X - offset / 2, rect.Y, rect.Width - offset, rect.Height);
217+
if (rect.Contains(location))
218+
{
219+
return i;
220+
}
221+
}
222+
return -1;
223+
}
224+
225+
private void tabMain_MouseUp(object sender, MouseEventArgs e)
226+
{
227+
_tabMoving = false;
228+
}
229+
193230
private void MainForm_MouseLeave(object sender, EventArgs e)
194231
{
195232
tabMain.ContextMenuStrip = null; //离开选项卡后 取消菜单
@@ -253,6 +290,7 @@ private void tmiDeleteAll_Click(object sender, EventArgs e)
253290
parent.Parent.Controls.Remove(parent);
254291
_currSelectHost = null;
255292
}
293+
256294
#endregion
257295

258296
}

RdpTest/Properties/Settings.Designer.cs

Lines changed: 13 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RdpTest/RdpTest.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
<OutputType>WinExe</OutputType>
99
<RootNamespace>RdpTest</RootNamespace>
1010
<AssemblyName>RdpTest</AssemblyName>
11-
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
11+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1414
<NuGetPackageImportStamp>
1515
</NuGetPackageImportStamp>
16+
<TargetFrameworkProfile />
1617
</PropertyGroup>
1718
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1819
<PlatformTarget>AnyCPU</PlatformTarget>

0 commit comments

Comments
 (0)