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

Commit

Permalink
增加拖拽变更选项卡位置的功能
Browse files Browse the repository at this point in the history
PS.以最low的方式实现的。。。
  • Loading branch information
xunki committed Apr 19, 2018
1 parent 2a7e34b commit 56ee714
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 46 deletions.
22 changes: 3 additions & 19 deletions RdpTest/App.config
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v13.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>

</configuration>
</configuration>
2 changes: 2 additions & 0 deletions RdpTest/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 47 additions & 9 deletions RdpTest/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,58 @@ private void btnAddRemoteHost_Click(object sender, EventArgs e)
#region 页签控制
private void tabMain_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
var index = InTabPageHead(e.Location);
if (index > 0)
{
for (int i = 1, count = tabMain.TabPages.Count; i < count; i++) //排除首页
tabMain.SelectedIndex = index;

if (e.Button == MouseButtons.Right)
tabMain.ContextMenuStrip = menuTabPage; //弹出菜单
else
_tabMoving = true;
}
}

/// <summary>
/// 正在移动 TabPage 位置
/// </summary>
private bool _tabMoving;
private void tabMain_MouseMove(object sender, MouseEventArgs e)
{
if (_tabMoving)
{
var index = InTabPageHead(e.Location);
if (index > 0 && tabMain.SelectedIndex != index)
{
var tp = tabMain.TabPages[i];
if (tabMain.GetTabRect(i).Contains(new Point(e.X, e.Y)))
{
tabMain.SelectedTab = tp;
tabMain.ContextMenuStrip = menuTabPage; //弹出菜单
break;
}
var currPage = tabMain.SelectedTab;

tabMain.TabPages.Remove(currPage);
tabMain.TabPages.Insert(index, currPage);
tabMain.SelectedTab = currPage;
}
}
}

private int InTabPageHead(Point location)
{
for (int i = 1, count = tabMain.TabPages.Count; i < count; i++) //排除首页
{
var rect = tabMain.GetTabRect(i);
var offset = rect.Width / 4;
rect = new Rectangle(rect.X - offset / 2, rect.Y, rect.Width - offset, rect.Height);
if (rect.Contains(location))
{
return i;
}
}
return -1;
}

private void tabMain_MouseUp(object sender, MouseEventArgs e)
{
_tabMoving = false;
}

private void MainForm_MouseLeave(object sender, EventArgs e)
{
tabMain.ContextMenuStrip = null; //离开选项卡后 取消菜单
Expand Down Expand Up @@ -253,6 +290,7 @@ private void tmiDeleteAll_Click(object sender, EventArgs e)
parent.Parent.Controls.Remove(parent);
_currSelectHost = null;
}

#endregion

}
Expand Down
30 changes: 13 additions & 17 deletions RdpTest/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion RdpTest/RdpTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
<OutputType>WinExe</OutputType>
<RootNamespace>RdpTest</RootNamespace>
<AssemblyName>RdpTest</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down

0 comments on commit 56ee714

Please sign in to comment.