一个WinForm的显示问题,求助!!
实际程序很负责,我按照大概意思写了个简单的示例,
代码如下,可以拷贝到vs.net2005中看执行结果,
怎么我加的两个工具栏显示了两行,要显示在同一行中还要设置什么?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace test
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public class Form1 : Form
{
public Form1()
{
ToolStripPanel tsp = new ToolStripPanel();
tsp.Dock = DockStyle.Top;
this.Controls.Add(tsp);
InitTS(tsp);
}
private void InitTS(ToolStripPanel tsp)
{
ToolStrip ts1 = new ToolStrip();
ts1.Text = "第一个工具栏 ";
ts1.Visible = false; // 注意这里设置了Visible = false,如果注释掉该行则显示是正常的
ToolStripButton tsi1 = new ToolStripButton( "第一个工具栏按钮 ");
ts1.Items.Add(tsi1);
ToolStrip ts2 = new ToolStrip();
ts2.Text = "第二个工具栏 ";
ts2.Visible = false; // 注意这里设置了Visible = false
ToolStripButton tsi21 = new ToolStripButton( "第二个工具栏按钮 ");
ts2.Items.Add(tsi21);
// 把工具栏添加到 ToolStripPanel 上面去
tsp.Join(ts1);
tsp.Join(ts2);
// 再改回可视
ts1.Visible = true;
ts2.Visible = true;
}
}
}
[解决办法]
tsp.Orientation = Orientation.Vertical;