
平台:C#窗口。 .Net Framework 3.5,4.0。 我有一些我想要显示为treevIEw的控件。 我已经将这组控件添加到treevIEw中,如下所示:
Control control; ................. ................. TreevIEw1.Controls.Add(control);
它显示了我像在面板树视图中的控制。 它没有显示任何层次结构或加号/减号。 所以我无法折叠/展开树节点。 请你给我一个解决的办法。
事件日志,P字段中的.NET运行时错误
为什么Process.MainWindowTitle总是空的,除了一个窗口?
我想创build一个安装在远程服务器上的应用程序安装程序
什么USB设备(友好名称)当前连接到PC?
寻找关于使用.NET和C ++托pipe与本地关系的build议
@Banketeshvar你可以使用Flowlayout面板或WPF扩展器。
WPF扩展代码是:
<Window x:Class="WpfExpander.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="MainWindow" Height="350" WIDth="525"> <GrID VerticalAlignment="Stretch" margin="3,3,3"> <GrID.RowDeFinitions> <RowDeFinition Height="0*" /> <RowDeFinition Height="85" /> <RowDeFinition Height="220" /> </GrID.RowDeFinitions> <Expander GrID.Row="1" header="expander1" name="expander1" IsExpanded="False"> <ListBox> <ListBoxItem Content="Unit 1"/> <ListBoxItem Content="Unit 2"/> </ListBox> </Expander> <Expander GrID.Row="2" header="expander2" name="expander2" IsExpanded="False"> <ListBox> <ListBoxItem Content="Unit 1"/> <ListBoxItem Content="Unit 2"/> </ListBox> </Expander> </GrID> </Window>
和FlowLayout面板代码是:
public partial class Form1 : Form { private bool _open; public Form1() { InitializeComponent(); this.flowLayoutPanel1.ClIEntSize = new Size(this.panel1.ClIEntSize.WIDth,0); } private voID button1_Click(object sender,EventArgs e) { if (_open) { this.flowLayoutPanel1.ClIEntSize = new Size(this.panel1.ClIEntSize.WIDth,0); //this.ClIEntSize = new Size(this.panel1.ClIEntSize.WIDth,this.panel1.ClIEntSize.Height); this.button1.Text = "+"; } else { //this.ClIEntSize = new Size(this.panel1.ClIEntSize.WIDth,this.panel1.ClIEntSize.Height + this.flowLayoutPanel1.PreferredSize.Height); this.flowLayoutPanel1.ClIEntSize= new Size(this.panel1.ClIEntSize.WIDth,this.panel1.ClIEntSize.Height + this.flowLayoutPanel1.PreferredSize.Height); this.button1.Text = "-"; } this._open = !this._open; } private voID button5_Click(object sender,EventArgs e) { button btn1=new button(); btn1.Text="aaaaaaaaaaaaaaaa"; flowLayoutPanel1.FlowDirection = FlowDirection.topDown; flowLayoutPanel1.Height += 100; flowLayoutPanel1.Controls.Add(btn1); } } } partial class Form1 { /// <summary> /// required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise,false.</param> protected overrIDe voID dispose(bool disposing) { if (disposing && (components != null)) { components.dispose(); } base.dispose(disposing); } #region windows Form Designer generated code /// <summary> /// required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private voID InitializeComponent() { this.panel1 = new System.windows.Forms.Panel(); this.label1 = new System.windows.Forms.Label(); this.button1 = new System.windows.Forms.button(); this.flowLayoutPanel1 = new System.windows.Forms.FlowLayoutPanel(); this.button5 = new System.windows.Forms.button(); this.panel1.SuspendLayout(); this.SuspendLayout(); // // panel1 // this.panel1.Controls.Add(this.label1); this.panel1.Controls.Add(this.button1); this.panel1.Location = new System.Drawing.Point(0,0); this.panel1.name = "panel1"; this.panel1.Size = new System.Drawing.Size(200,30); this.panel1.TabIndex = 0; // // label1 // this.label1.autoSize = true; this.label1.Location = new System.Drawing.Point(127,9); this.label1.name = "label1"; this.label1.Size = new System.Drawing.Size(35,13); this.label1.TabIndex = 1; this.label1.Text = "label1"; // // button1 // this.button1.Location = new System.Drawing.Point(4,4); this.button1.name = "button1"; this.button1.Size = new System.Drawing.Size(75,23); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.UseVisualStyleBackcolor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // flowLayoutPanel1 // this.flowLayoutPanel1.Backcolor = System.Drawing.color.Sandybrown; this.flowLayoutPanel1.Location = new System.Drawing.Point(4,36); this.flowLayoutPanel1.name = "flowLayoutPanel1"; this.flowLayoutPanel1.Size = new System.Drawing.Size(553,289); this.flowLayoutPanel1.TabIndex = 1; // // button5 // this.button5.Location = new System.Drawing.Point(38,389); this.button5.name = "button5"; this.button5.Size = new System.Drawing.Size(75,23); this.button5.TabIndex = 2; this.button5.Text = "Add buttons"; this.button5.UseVisualStyleBackcolor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // // Form1 // this.autoScaleDimensions = new System.Drawing.Sizef(6F,13F); this.autoScaleMode = System.windows.Forms.autoScaleMode.Font; this.ClIEntSize = new System.Drawing.Size(840,453); this.Controls.Add(this.button5); this.Controls.Add(this.flowLayoutPanel1); this.Controls.Add(this.panel1); this.name = "Form1"; this.Text = "Form1"; this.panel1.ResumeLayout(false); this.panel1.Performlayout(); this.ResumeLayout(false); } #endregion private System.windows.Forms.Panel panel1; private System.windows.Forms.Label label1; private System.windows.Forms.button button1; private System.windows.Forms.FlowLayoutPanel flowLayoutPanel1; private System.windows.Forms.button button5; }
如果不在运行时添加控件,则可以使用简单的Panel Control而不是FlowLayoutPanelControl。
您也可以使用普通的Panel Control进行动态控制,但FlowLayoutPanel提供了一些附加属性。
总结以上是内存溢出为你收集整理的控件的树视图与崩溃/展开全部内容,希望文章能够帮你解决控件的树视图与崩溃/展开所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)