TabControl和TreeView的综合使用问题

lightingstorm 2006-11-02 10:26:12
现在用TreeView实现页面的导航,页面内容的设计要使用TabControl,方便实现切换和布局调整。但是不想让TabControl的导航标签显示。就是说,不用也不显示TabControl的导航标签,只使用TreeView的导航功能。怎么办???
...全文
389 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovvver 2006-11-03
  • 打赏
  • 举报
回复
你做的导航,类似于向导那样的吗?
如果是的话,你可以尝试用MagicLibrary.dll里的WizardForm。
或者你可以到codeproject里找wizard方面的控件。
oolongTea 2006-11-03
  • 打赏
  • 举报
回复
还可按需添加和删除
tabControl1.Controls.Remove(tabPage1);
tabControl1.Controls.Add(tabPage1);
oolongTea 2006-11-03
  • 打赏
  • 举报
回复
另一种做法(头两句可不加)

//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));
oolongTea 2006-11-03
  • 打赏
  • 举报
回复
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;
}
}
}
北京的雾霾天 2006-11-02
  • 打赏
  • 举报
回复
TabControl不能做到不显示上面的按钮,要是想做到界面的动态切换,可以用动态加载Control或UserControl或没有边框的Form到主界面里来实现。
发帖
C#

10.9w+

社区成员

.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
帖子事件
创建了帖子
2006-11-02 10:26
社区公告

让您成为最强悍的C#开发者