在csdn下载了一个类似ie7的功能,使用的是默认的TabControl控件 窗体算比较丑 功能是实现了 废话不多说 贴代码
1:先上图
2:贴代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int isclicktwo = 0;
private void tabControl1_MouseUp(object sender, MouseEventArgs e)
{
if (this.tabControl1.SelectedIndex == 0) return;
if (e.Button == MouseButtons.Right)
{
for (int i = 1; i < tabControl1.TabPages.Count; i++)
{
TabPage tp = tabControl1.TabPages[i];
if (tabControl1.GetTabRect(i).Contains(new Point(e.X, e.Y)))
{
tabControl1.SelectedTab = tp;
this.contextMenuStrip1.Show(this.tabControl1, new Point(e.X, e.Y));
break;
}
}
}
if (e.Button == MouseButtons.Left)
{
isclicktwo++;
Rectangle myTabRect = this.tabControl1.GetTabRect(this.tabControl1.SelectedIndex);
int width = myTabRect.Width / 4;
int height=myTabRect .Height ;
Rectangle closeRect = new Rectangle(myTabRect.X, myTabRect.Y, width, height);
if (closeRect.Contains(new Point(e.X, e.Y)))
{
if(isclicktwo >=2)
{
this.tabControl1.TabPages.Remove(this.tabControl1.SelectedTab);
isclicktwo = 0;
}
}
}
}
private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.tabControl1.TabPages.Remove(this.tabControl1.SelectedTab);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 1; i < this.tabControl1.TabPages.Count; i++)
{
if(this.tabControl1.TabPages [i].ImageIndex!=-1)
{
this.tabControl1.TabPages[i].ImageIndex = -1;
}
}
if (this.tabControl1.SelectedIndex == 0) return;
this.tabControl1.SelectedTab .ImageIndex =0;
isclicktwo = 0;//转换页清零
}
private void tabControl1_MouseDown(object sender, MouseEventArgs e)
{
if (this.tabControl1.SelectedIndex == 0) return;
if (e.Button == MouseButtons.Left)
{
Rectangle myTabRect = this.tabControl1.GetTabRect(this.tabControl1.SelectedIndex);
int width = myTabRect.Width / 4;
int height = myTabRect.Height;
Rectangle closeRect = new Rectangle(myTabRect.X, myTabRect.Y, width, height);
if (closeRect.Contains(new Point(e.X, e.Y)))
{
this.tabControl1.TabPages[this.tabControl1.SelectedIndex].ImageIndex = 1;
Application.DoEvents();
}
}
}
private void tabControl1_MouseLeave(object sender, EventArgs e)
{
if (this.tabControl1.SelectedIndex == 0) return;
this.tabControl1.TabPages[this.tabControl1.SelectedIndex].ImageIndex = 0;
}
}
}
功能还需完善 思路已出