首先你要知道tabcontro控件的基本属性,不会的话在微软的官方帮助文档里面是有的:
一般你已经在网上找了相当多的帮助文件,但是由于你不是很熟悉缺少了
这两个属性的配置,对于一般的菜鸟来说是不知道的,所以要在此处点出来
接下来是cs的源码
#region 右面显示部分逻辑
public void Add_TabPage(Form myForm)
{
if (tabControlCheckHave(this.tabControlShowForm, myForm.Text))
{
return;
}
else
{
tabControlShowForm.TabPages.Add(myForm.Text);
tabControlShowForm.SelectTab(tabControlShowForm.TabPages.Count - 1);
myForm.FormBorderStyle = FormBorderStyle.None;
myForm.Dock = DockStyle.Fill;
myForm.TopLevel = false;
myForm.Show();
myForm.Parent = tabControlShowForm.SelectedTab;
}
}
private bool tabControlCheckHave(System.Windows.Forms.TabControl tab, String tabName)
{
for (int i = 0; i < tab.TabCount; i++)
{
if (tab.TabPages[i].Text == tabName)
{
tab.SelectedIndex = i;
return true;
}
}
return false;
}
private void tabControlShowForm_DrawItem(object sender, DrawItemEventArgs e)
{
try
{
this.tabControlShowForm.TabPages[e.Index].BackColor = Color.LightBlue;
Rectangle tabRect = this.tabControlShowForm.GetTabRect(e.Index);
e.Graphics.DrawString(this.tabControlShowForm.TabPages[e.Index].Text, this.Font, SystemBrushes.ControlText, (float)(tabRect.X + 2), (float)(tabRect.Y + 2));
using (Pen pen = new Pen(Color.White))
{
tabRect.Offset(tabRect.Width - 15, 2);
tabRect.Width = 15;
tabRect.Height = 15;
e.Graphics.DrawRectangle(pen, tabRect);
}
Color color = (e.State == DrawItemState.Selected) ? Color.LightBlue : Color.White;
using (Brush brush = new SolidBrush(color))
{
e.Graphics.FillRectangle(brush, tabRect);
}
using (Pen pen2 = new Pen(Color.Red))
{
Point point = new Point(tabRect.X + 3, tabRect.Y + 3);
Point point2 = new Point((tabRect.X + tabRect.Width) - 3, (tabRect.Y + tabRect.Height) - 3);
e.Graphics.DrawLine(pen2, point, point2);
Point point3 = new Point(tabRect.X + 3, (tabRect.Y + tabRect.Height) - 3);
Point point4 = new Point((tabRect.X + tabRect.Width) - 3, tabRect.Y + 3);
e.Graphics.DrawLine(pen2, point3, point4);
}
e.Graphics.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void tabControlShowForm_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int x = e.X;
int y = e.Y;
Rectangle tabRect = this.tabControlShowForm.GetTabRect(this.tabControlShowForm.SelectedIndex);
tabRect.Offset(tabRect.Width - 0x12, 2);
tabRect.Width = 15;
tabRect.Height = 15;
if ((((x > tabRect.X) && (x < tabRect.Right)) && (y > tabRect.Y)) && (y < tabRect.Bottom))
{
this.tabControlShowForm.TabPages.Remove(this.tabControlShowForm.SelectedTab);
}
}
}
private void tabControlShowForm_SelectedIndexChanged(object sender, EventArgs e)
{
this.tabControl.SelectedIndex = 4;
String seletedTabpage = this.tabControlShowForm.SelectedTab.Text.ToString();
if(seletedTabpage.Equals("燃料数据导入"))
{
if (_tabCljbWriteForm == null)
{
_tabCljbWriteForm = new TabCljbWriteForm();
}
this.tabPageOperaShow(_tabCljbWriteForm);
}
else if (seletedTabpage.Equals("待上报"))
{
if (_tabSearchLocalForm == null)
{
_tabSearchLocalForm = new TabSearchLocalForm();
}
this.tabPageOperaShow(_tabSearchLocalForm);
}
else if (seletedTabpage.Equals("补传待上报"))
{
if (_tabSearchLocalOTForm == null)
{
_tabSearchLocalOTForm = new TabSearchLocalOTForm();
}
this.tabPageOperaShow(_tabSearchLocalOTForm);
}
else if (seletedTabpage.Equals("已上报"))
{
if (_tabSearchLocalUploadForm == null)
{
_tabSearchLocalUploadForm = new TabSearchLocalUploadForm();
}
this.tabPageOperaShow(_tabSearchLocalUploadForm);
}
else if (seletedTabpage.Equals("已修改未上报"))
{
if (_tabSearchLocalUpdateForm == null)
{
_tabSearchLocalUpdateForm = new TabSearchLocalUpdateForm();
}
this.tabPageOperaShow(_tabSearchLocalUpdateForm);
}
else if (seletedTabpage.Equals("远程查询"))
{
if (_tabSearchServerForm == null)
{
_tabSearchServerForm = new TabSearchServerForm();
}
this.tabPageOperaShow(_tabSearchServerForm);
}
else if (seletedTabpage.Equals("补传申请查询"))
{
if (_tabApplyUpOTViewForm == null)
{
_tabApplyUpOTViewForm = new TabApplyUpOTViewForm();
}
this.tabPageOperaShow(_tabApplyUpOTViewForm);
}
else if (seletedTabpage.Equals("修改申请查询"))
{
if (_tabApplyEditViewForm == null)
{
_tabApplyEditViewForm = new TabApplyEditViewForm();
}
this.tabPageOperaShow(_tabApplyEditViewForm);
}
else if (seletedTabpage.Equals("撤销申请查询"))
{
if (_tabApplyDelViewForm == null)
{
_tabApplyDelViewForm = new TabApplyDelViewForm();
}
this.tabPageOperaShow(_tabApplyDelViewForm);
}
else if (seletedTabpage.Equals("数据上报统计"))
{
if (_tabCountDataUpForm == null)
{
_tabCountDataUpForm = new TabCountDataUpForm();
}
this.tabPageOperaShow(_tabCountDataUpForm);
}
else if (seletedTabpage.Equals("平均油耗参数明细"))
{
if (_tabCountAverageFuelForm == null)
{
_tabCountAverageFuelForm = new TabCountAverageFuelForm();
}
this.tabPageOperaShow(_tabCountAverageFuelForm);
}
else if (seletedTabpage.Equals("平均油耗查询"))
{
if (_tabCountAveFulSechForm == null)
{
_tabCountAveFulSechForm = new TabCountAveFulSechForm();
}
this.tabPageOperaShow(_tabCountAveFulSechForm);
}
else if (seletedTabpage.Equals("平均油耗预测"))
{
if (_tabCountAveFulFureForm == null)
{
_tabCountAveFulFureForm = new TabCountAveFulFureForm();
}
this.tabPageOperaShow(_tabCountAveFulFureForm);
}
else if (seletedTabpage.Equals("燃料参数同步"))
{
if (_tabSyncParamForm == null)
{
_tabSyncParamForm = new TabSyncParamForm();
}
this.tabPageOperaShow(_tabSyncParamForm);
}
else if(seletedTabpage.Equals("节假日数据同步"))
{
if (_tabSyncHolidayForm == null)
{
_tabSyncHolidayForm = new TabSyncHolidayForm();
}
this.tabPageOperaShow(_tabSyncHolidayForm);
}
}
#endregion
}
看完这一部分,基本上面你已经全部完成了,接下来编译通过后,就可以执行文件了!效果如图