TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Paul
NA
1
0
TableLayoutPanel content control stretching
Mar 11 2007 6:13 PM
using System.Drawing; using System.Windows.Forms; public class Test { Form form; GroupBox groupBox; TableLayoutPanel tableLayoutPanel; Label label; TextBox textBox; Button button; public Test() { this.form = new Form(); this.form.Text = "Test"; this.form.MinimumSize = new Size(600, 300); this.groupBox = new GroupBox(); this.groupBox.Text = "Input"; this.groupBox.Dock = DockStyle.Fill; this.tableLayoutPanel = new TableLayoutPanel(); this.tableLayoutPanel.Dock = DockStyle.Fill; this.tableLayoutPanel.ColumnCount = 3; this.tableLayoutPanel.RowCount = 1; this.tableLayoutPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single; this.label = new Label(); this.label.Text = "Input file:"; this.label.Anchor = (AnchorStyles) (AnchorStyles.Top | AnchorStyles.Left); this.textBox = new TextBox(); this.textBox.Text = "Test"; this.textBox.Anchor = (AnchorStyles) (AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right); this.textBox.Dock = DockStyle.Fill; this.button = new Button(); this.button.Text = "Browse..."; this.button.Anchor = (AnchorStyles) (AnchorStyles.Top | AnchorStyles.Right); this.tableLayoutPanel.Controls.Add(this.label, 0, 0); this.tableLayoutPanel.Controls.Add(this.textBox, 1, 0); this.tableLayoutPanel.Controls.Add(this.button, 2, 0); this.groupBox.Controls.Add(this.tableLayoutPanel); this.form.Controls.Add(this.groupBox); this.form.ShowDialog(); } public static void Main() { new Test(); } } /* When compiling this, the textbox does not appear, I'm assuming because of the Anchoring and the column it's within can't AutoSize.. Anyway, if you switch the order of addition to the tableLayoutPanel between the button and textBox, e.g.: this.tableLayoutPanel.Controls.Add(this.label, 0, 0); this.tableLayoutPanel.Controls.Add(this.textBox, 2, 0); this.tableLayoutPanel.Controls.Add(this.button, 1, 0); The textBox appears, and stretches when resizing. *** This is the desired effect however with the textBox situated in the middle row ***. The only solution I've come up with so far is the following: this.tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, this.label.Width)); this.tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100)); this.tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, this.button.Width)); Which doesn't seem too nice and causes some delay on Windows while resizing as it tries to update and gets caught up in some presumed resize calculation loop for a second or two with the desktop Icons and the application itself flickering away. */
Reply
Answers (
1
)
flash transparent
How to display an OpenFileDialog when changing a property in a PropertyGrid?