Fragensteller
TableLayout mit Anchor in Panel zum Scrollen will nicht

Frage
-
Hallo zusammen,
ich habe mir ein Panel in eine groupBox mit Dock=Fill gelegt. Das Panel ist auf AutoScroll=True. In diesem Panel habe ich dann noch ein TableLayout mit zwei Spalten und 3 Zeilen. Die erste und letzte Zeile sind auf AutoSize und im Grunde fix von der Größe her. Das TableLayout hat momentan einen Top-, Left-, Right-Anchor
Wenn ich das Form von der Höhe her sehr klein mache, erscheint wie gewünscht die ScrollBar im Panel. Wenn ich aber das Form von der Höhe her größer mache, sollte eigentlich das DataGridView wachsen, das sich im TableLayout in Zeiel 2 befindet. Das tut es natürlich nicht, weil das TableLayout den Bottom-Anchor nicht gesetzt hat. Setze ich den aber, dann erscheinen die ScrollBars im Panel nicht mehr, wenn die Höhe zu klein wird.
Eigentlich würde ich sagen, müsste das TableLayout eine MinimumHeight haben und einen Bottom-Anchor. Leider geht das Scrollen dann nicht mehr. Lässt sich das Problem irgendwie lösen, oder geht das so eben einfach nicht?
Alle Antworten
-
Hallo SP.,
auch, wenn Du ja normal nicht auf meine Antworten reagierst, hier ein paar Infos dazu ggf. für andere, die das Problem haben.
Mit folgendem Design sollte es funktionieren. Poste ruhig einfach den Designer-Code (aus der **.Designer.cs), damit wir Dein Szenario nachvollziehen können.Hier der Designer-Code in meinem funktionierenden Beispiel:
namespace WinTableTest { partial class Form1 { /// <summary> /// Erforderliche Designervariable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Verwendete Ressourcen bereinigen. /// </summary> /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Vom Windows Form-Designer generierter Code /// <summary> /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// </summary> private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); this.panel1 = new System.Windows.Forms.Panel(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.dataGridView2 = new System.Windows.Forms.DataGridView(); this.groupBox1.SuspendLayout(); this.panel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.Add(this.panel1); this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.groupBox1.Location = new System.Drawing.Point(0, 0); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(419, 357); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "groupBox1"; // // panel1 // this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.panel1.AutoScroll = true; this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); this.panel1.Controls.Add(this.tableLayoutPanel1); this.panel1.Location = new System.Drawing.Point(12, 29); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(378, 307); this.panel1.TabIndex = 1; // // tableLayoutPanel1 // this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); this.tableLayoutPanel1.ColumnCount = 2; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.Controls.Add(this.dataGridView1, 0, 1); this.tableLayoutPanel1.Controls.Add(this.dataGridView2, 1, 1); this.tableLayoutPanel1.Location = new System.Drawing.Point(17, 23); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 3; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.Size = new System.Drawing.Size(335, 186); this.tableLayoutPanel1.TabIndex = 0; // // dataGridView1 // this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.Location = new System.Drawing.Point(3, 3); this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.Size = new System.Drawing.Size(161, 150); this.dataGridView1.TabIndex = 0; // // dataGridView2 // this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView2.Location = new System.Drawing.Point(170, 3); this.dataGridView2.Name = "dataGridView2"; this.dataGridView2.Size = new System.Drawing.Size(162, 150); this.dataGridView2.TabIndex = 1; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(419, 357); this.Controls.Add(this.groupBox1); this.Name = "Form1"; this.Text = "Form1"; this.groupBox1.ResumeLayout(false); this.panel1.ResumeLayout(false); this.tableLayoutPanel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.DataGridView dataGridView1; private System.Windows.Forms.DataGridView dataGridView2; } }
ciao Frank -
Hallo Frank,
dass ich auf Deine Postings nicht antworte, stimmt nicht!! Ich hatte vielleicht beim letzten Mal nur auf das erste Posting zu meiner Frage geantwortet, habe das aber nicht mehr richtig in Erinnerung. Wenn das so rüber kommen sollte, dann ist das Zufall und hat nichts mit Qualität der vorgeschlagenen Lösungen oder sonst etwas zu tun! Sorry, wenn das so rüber gekommen ist. Ausserdem hatte ich auch Deine Postings als Antwort markiert!
So, zurück zum Problem: Ich habe Dein Beispiel nochmals erweitert, damit man sehen kann, wie es bei mir aussieht und warum das nicht klappt. Man sieht, dass nur die DataGridViews in der Höhe erweitert werden, aber wenn diese eine bestimmte Mindesthöhe erreicht haben, erscheinen die Scrollbars nicht. Ich hätte es eben gerne so, dass wenn die aktuell festgelegte Höhe unterschritten wird, die Scrollbars erscheinen, aber wenn die Höhe größer wird, als aktuell festgelegt, nur das DataGridView wächst (das funktioniert ja schon sehr gut!):
namespace WindowsApplication6 { partial class Form1 { /// <summary> /// Erforderliche Designervariable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Verwendete Ressourcen bereinigen. /// </summary> /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Vom Windows Form-Designer generierter Code /// <summary> /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// </summary> private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); this.panel1 = new System.Windows.Forms.Panel(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.dataGridView2 = new System.Windows.Forms.DataGridView(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.panel2 = new System.Windows.Forms.Panel(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.checkBox3 = new System.Windows.Forms.CheckBox(); this.checkBox4 = new System.Windows.Forms.CheckBox(); this.panel3 = new System.Windows.Forms.Panel(); this.checkBox5 = new System.Windows.Forms.CheckBox(); this.checkBox6 = new System.Windows.Forms.CheckBox(); this.groupBox1.SuspendLayout(); this.panel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit(); this.panel2.SuspendLayout(); this.panel3.SuspendLayout(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.Add(this.panel1); this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.groupBox1.Location = new System.Drawing.Point(0, 0); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(419, 357); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "groupBox1"; // // panel1 // this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.panel1.AutoScroll = true; this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); this.panel1.Controls.Add(this.tableLayoutPanel1); this.panel1.Location = new System.Drawing.Point(12, 29); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(378, 307); this.panel1.TabIndex = 1; // // tableLayoutPanel1 // this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); this.tableLayoutPanel1.ColumnCount = 2; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.Controls.Add(this.dataGridView1, 0, 1); this.tableLayoutPanel1.Controls.Add(this.dataGridView2, 1, 1); this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); this.tableLayoutPanel1.Controls.Add(this.label2, 1, 0); this.tableLayoutPanel1.Controls.Add(this.panel2, 0, 2); this.tableLayoutPanel1.Controls.Add(this.panel3, 1, 2); this.tableLayoutPanel1.Location = new System.Drawing.Point(17, 23); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 3; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.Size = new System.Drawing.Size(335, 269); this.tableLayoutPanel1.TabIndex = 0; // // dataGridView1 // this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; this.dataGridView1.Location = new System.Drawing.Point(3, 23); this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.Size = new System.Drawing.Size(161, 137); this.dataGridView1.TabIndex = 0; // // dataGridView2 // this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView2.Dock = System.Windows.Forms.DockStyle.Fill; this.dataGridView2.Location = new System.Drawing.Point(170, 23); this.dataGridView2.Name = "dataGridView2"; this.dataGridView2.Size = new System.Drawing.Size(162, 137); this.dataGridView2.TabIndex = 1; // // label1 // this.label1.Anchor = System.Windows.Forms.AnchorStyles.Left; this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(3, 3); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(46, 13); this.label1.TabIndex = 2; this.label1.Text = "Spalte 1"; // // label2 // this.label2.Anchor = System.Windows.Forms.AnchorStyles.Left; this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(170, 3); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(46, 13); this.label2.TabIndex = 3; this.label2.Text = "Spalte 2"; // // panel2 // this.panel2.Controls.Add(this.checkBox4); this.panel2.Controls.Add(this.checkBox3); this.panel2.Controls.Add(this.checkBox2); this.panel2.Controls.Add(this.checkBox1); this.panel2.Location = new System.Drawing.Point(3, 166); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(161, 100); this.panel2.TabIndex = 4; // // checkBox1 // this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(3, 3); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(80, 17); this.checkBox1.TabIndex = 0; this.checkBox1.Text = "checkBox1"; this.checkBox1.UseVisualStyleBackColor = true; // // checkBox2 // this.checkBox2.AutoSize = true; this.checkBox2.Location = new System.Drawing.Point(3, 26); this.checkBox2.Name = "checkBox2"; this.checkBox2.Size = new System.Drawing.Size(80, 17); this.checkBox2.TabIndex = 1; this.checkBox2.Text = "checkBox2"; this.checkBox2.UseVisualStyleBackColor = true; // // checkBox3 // this.checkBox3.AutoSize = true; this.checkBox3.Location = new System.Drawing.Point(3, 49); this.checkBox3.Name = "checkBox3"; this.checkBox3.Size = new System.Drawing.Size(80, 17); this.checkBox3.TabIndex = 2; this.checkBox3.Text = "checkBox3"; this.checkBox3.UseVisualStyleBackColor = true; // // checkBox4 // this.checkBox4.AutoSize = true; this.checkBox4.Location = new System.Drawing.Point(3, 72); this.checkBox4.Name = "checkBox4"; this.checkBox4.Size = new System.Drawing.Size(80, 17); this.checkBox4.TabIndex = 3; this.checkBox4.Text = "checkBox4"; this.checkBox4.UseVisualStyleBackColor = true; // // panel3 // this.panel3.Controls.Add(this.checkBox6); this.panel3.Controls.Add(this.checkBox5); this.panel3.Location = new System.Drawing.Point(170, 166); this.panel3.Name = "panel3"; this.panel3.Size = new System.Drawing.Size(162, 100); this.panel3.TabIndex = 5; // // checkBox5 // this.checkBox5.AutoSize = true; this.checkBox5.Location = new System.Drawing.Point(3, 3); this.checkBox5.Name = "checkBox5"; this.checkBox5.Size = new System.Drawing.Size(80, 17); this.checkBox5.TabIndex = 0; this.checkBox5.Text = "checkBox5"; this.checkBox5.UseVisualStyleBackColor = true; // // checkBox6 // this.checkBox6.AutoSize = true; this.checkBox6.Location = new System.Drawing.Point(3, 26); this.checkBox6.Name = "checkBox6"; this.checkBox6.Size = new System.Drawing.Size(80, 17); this.checkBox6.TabIndex = 1; this.checkBox6.Text = "checkBox6"; this.checkBox6.UseVisualStyleBackColor = true; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(419, 357); this.Controls.Add(this.groupBox1); this.Name = "Form1"; this.Text = "Form1"; this.groupBox1.ResumeLayout(false); this.panel1.ResumeLayout(false); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit(); this.panel2.ResumeLayout(false); this.panel2.PerformLayout(); this.panel3.ResumeLayout(false); this.panel3.PerformLayout(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.DataGridView dataGridView1; private System.Windows.Forms.DataGridView dataGridView2; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Panel panel2; private System.Windows.Forms.CheckBox checkBox4; private System.Windows.Forms.CheckBox checkBox3; private System.Windows.Forms.CheckBox checkBox2; private System.Windows.Forms.CheckBox checkBox1; private System.Windows.Forms.Panel panel3; private System.Windows.Forms.CheckBox checkBox6; private System.Windows.Forms.CheckBox checkBox5; } }
-
Hallo SP.,
in Deinem Beispiel sind ja nun gar keine ScrollBars mehr (also nicht so, wie Du am Anfang angegeben hattest).
Du möchtest also, dass wenn eine bestimmte Höhe der Grids (sagen wir mal 100) erreicht ist, dass ScrollBars angezeigt werden sagen wir mal in Row2 des TableLayoutPanels, oder panel1?
panel1, den Du auf AutoScroll gestellt hast, kann ja nicht scrollen, da er gegen den Bottom geanchort ist, und so mitwächst und die inneren Controls ja auch nicht grösser wachsen, als panels1. Nur dann würde er ScrollBars anzeigen.
Die nur als Idee/Hinweis, um das Thema ggf. etwas klarer zu machen.
ciao Frank -
Hallo Frank,
sorry für das späte Reagieren auf den Beitrag. War über das WE nicht erreichbar.
Nun ja, dass keine Scrollbars mehr in meinem Beispiel erscheinen, ist genau das Problem und meine Vermutung stimmt wohl, dass das mit einem Bottom-Anchor auch nicht zu erreichen ist, oder?
Ich hätte mir das eigentlich so vorgestellt, dass der man dem DataGridView irgendwie eine minimale Höhe vorgeben kann. Das DataGridView und auch das TableLayout sind so angedockt wie im Beispiel von mir. Einziger Unterschied: sobald das DataGridView kleiner wird als die vorgegebene minimale Höhe, sollen ScrollBars im Panel erscheinen. Ich hatte gehofft, dass das mit AutoScroll=true im Panel geht, leider aber nicht.
Das Verhalten wäre dann ganz schön, weil das DataGridView eben dann nie unter eine minimale Höhe kommt und damit der Inhalt noch schön sichtbar ist. Wenn der User auf dem Bildschirm mehr Platz nach oben hat, könnte er das Form auch höher machen und somit wäre noch mehr Inhalt des DataGridViews zu sehen. Reicht der Platz allerdings nicht nach oben aus und der User muss das Form kleiner machen, dann würden zumindest die ScrollBars des Panels erscheinen und das DataGridView wäre eben auf seine festgelegte Minimale Höhe fixiert. der Rest müsste der User eben dann scrollen.
So war die Hoffnung ;-)
Ich schätze mal, dass sich das so wohl eher nicht realisieren lässt, oder hast Du noch eine Idee?