TabControl和TreeView的综合使用问题 现在用TreeView实现页面的导航,页面内容的设计要使用TabControl,方便实现切换和布局调整。但是不想让TabControl的导航标签显示。就是说,不用也不显示TabControl的导航标签,只使用TreeView的导航功能。怎么办??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 TabControl不能做到不显示上面的按钮,要是想做到界面的动态切换,可以用动态加载Control或UserControl或没有边框的Form到主界面里来实现。 using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace WindowsApplication1{ public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage2 = new System.Windows.Forms.TabPage(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); this.tabPage2.SuspendLayout(); this.SuspendLayout(); // // tabControl1 // this.tabControl1.Alignment = System.Windows.Forms.TabAlignment.Right; this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Controls.Add(this.tabPage2); this.tabControl1.Location = new System.Drawing.Point(88, 0); this.tabControl1.Multiline = true; this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(352, 304); this.tabControl1.TabIndex = 0; // // tabPage1 // this.tabPage1.Controls.Add(this.label1); this.tabPage1.Location = new System.Drawing.Point(4, 4); this.tabPage1.Name = "tabPage1"; this.tabPage1.Size = new System.Drawing.Size(225, 280); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "tabPage1"; // // tabPage2 // this.tabPage2.Controls.Add(this.label2); this.tabPage2.Location = new System.Drawing.Point(4, 4); this.tabPage2.Name = "tabPage2"; this.tabPage2.Size = new System.Drawing.Size(325, 296); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "tabPage2"; // // label1 // this.label1.Location = new System.Drawing.Point(72, 88); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(152, 32); this.label1.TabIndex = 0; this.label1.Text = "Page 1"; // // label2 // this.label2.Location = new System.Drawing.Point(64, 112); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(200, 32); this.label2.TabIndex = 0; this.label2.Text = "Page 2"; // // button1 // this.button1.Location = new System.Drawing.Point(16, 80); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(64, 24); this.button1.TabIndex = 1; this.button1.Text = "Page 1"; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(16, 120); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(64, 24); this.button2.TabIndex = 2; this.button2.Text = "Page 2"; this.button2.Click += new System.EventHandler(this.button2_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(410, 296); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Controls.Add(this.tabControl1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Name = "Form1"; this.Text = "Form1"; this.tabControl1.ResumeLayout(false); this.tabPage1.ResumeLayout(false); this.tabPage2.ResumeLayout(false); this.ResumeLayout(false); } #endregion [STAThread] static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { tabControl1.SelectedIndex = 0; } private void button2_Click(object sender, System.EventArgs e) { tabControl1.SelectedIndex = 1; } }} 另一种做法(头两句可不加)//tabControl1.Top = tabControl1.Top - tabControl1.ItemSize.Height; //tabControl1.Height = tabControl1.Height + tabControl1.ItemSize.Height;tabControl1.Region = new Region(new RectangleF(tabPage1.Left, tabPage1.Top, tabPage1.Width, tabPage1.Height + tabControl1.ItemSize.Height)); 还可按需添加和删除tabControl1.Controls.Remove(tabPage1);tabControl1.Controls.Add(tabPage1); 你做的导航,类似于向导那样的吗?如果是的话,你可以尝试用MagicLibrary.dll里的WizardForm。或者你可以到codeproject里找wizard方面的控件。 【求助】如何让托盘监控程序获取某网页的文档对象模型 如何实现浏览器左上角前进后退按钮不可用,加急!!! 如何让子窗体强制置于当前? 怎么样在EXCEL表打开情况下把数据读出来 新手请教:如何实现循环 .aspx中的DataGrid能不能实现这样的一个绑定方式??? 为何按书上或C#例子上做,oldDbDataAdapter1.Update(table)总是出错? 简单的多线程问题,哪位好心人告诉我哪里错了 Nhibernate 多对多映射 中间表的主键问题 请问《展现C#》的英文名是什么 有人做过bolg站点吗?知道的来看一下 关于.net 2005的 全局hook问题。
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
} protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
private void InitializeComponent()
{
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Alignment = System.Windows.Forms.TabAlignment.Right;
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(88, 0);
this.tabControl1.Multiline = true;
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(352, 304);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.label1);
this.tabPage1.Location = new System.Drawing.Point(4, 4);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(225, 280);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
//
// tabPage2
//
this.tabPage2.Controls.Add(this.label2);
this.tabPage2.Location = new System.Drawing.Point(4, 4);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(325, 296);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
//
// label1
//
this.label1.Location = new System.Drawing.Point(72, 88);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(152, 32);
this.label1.TabIndex = 0;
this.label1.Text = "Page 1";
//
// label2
//
this.label2.Location = new System.Drawing.Point(64, 112);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(200, 32);
this.label2.TabIndex = 0;
this.label2.Text = "Page 2";
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 80);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 24);
this.button1.TabIndex = 1;
this.button1.Text = "Page 1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(16, 120);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 24);
this.button2.TabIndex = 2;
this.button2.Text = "Page 2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(410, 296);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.tabControl1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "Form1";
this.Text = "Form1";
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.ResumeLayout(false); }
#endregion [STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
tabControl1.SelectedIndex = 0;
} private void button2_Click(object sender, System.EventArgs e)
{
tabControl1.SelectedIndex = 1;
}
}
}
//tabControl1.Height = tabControl1.Height + tabControl1.ItemSize.Height;
tabControl1.Region = new Region(new RectangleF(tabPage1.Left, tabPage1.Top, tabPage1.Width, tabPage1.Height + tabControl1.ItemSize.Height));
tabControl1.Controls.Remove(tabPage1);
tabControl1.Controls.Add(tabPage1);
如果是的话,你可以尝试用MagicLibrary.dll里的WizardForm。
或者你可以到codeproject里找wizard方面的控件。