473,388 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

TableLayoutPanel problem

WP
Hello, I'm trying to write a C# version of a simple Java program (that
uses swing for its gui). I'm using Visual C# 9.0 SP1 (2008) and I'm
using winforms for the gui.

Here's my problem. I want a TableLayoutPanel to cover the entire client
area of my form. The TableLayoutPanel should have two rows and five
columns and each cell should have the same size. Most cells will contain
buttons but some cells will contains labels. The control in a cell
should stretch across the entire cell. Some buttons will have an image
instead of text and I want the image to be centered when the cell is
bigger than the image, if that's possible. Labels should have
left-aligned text in the vertical middle.

Here's my attempt:

Here's what I do with the TableLayoutPanel:
tblLayoutPanel.Dock = DockStyle.Fill;
tblLayoutPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
tblLayoutPanel.ColumnCount = 5;
tblLayoutPanel.RowCount = 2;
tblLayoutPanel.AutoSize = true;
tblLayoutPanel.ColumnStyles.Clear();
tblLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20));
tblLayoutPanel.RowStyles.Clear();
tblLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 50));

Here's how buttons and labels are created:
private Button CreateButton(string fileName, string buttonText) {
Button b = new Button();

if (fileName != null)
{
b.BackgroundImage = Image.FromFile(fileName);
}
else
{
b.Text = buttonText;
}

b.Anchor = AnchorStyles.Bottom | AnchorStyles.Top |
AnchorStyles.Left | AnchorStyles.Right;

return b;
}

private Label CreateLabel(string initialText) {
Label l = new Label();

l.Text = initialText;
l.TextAlign = ContentAlignment.MiddleLeft;

l.Anchor = AnchorStyles.Bottom | AnchorStyles.Top |
AnchorStyles.Left | AnchorStyles.Right;

return l;
}

With properties above I dont get the desired behavior, here's how it looks:
The TableLayoutPanel fills the entire client area of the form: Good.
The TableLayoutPanel has two rows with five columns: Good.
The contents of the cells (a label or a button) seems to fill the entire
cell: Good.
However, the cells are not of equal size (neither width nor height). The
top row, which contains just buttons with images, is much much higher
than the bottom row (which contains labels and buttons). The first
column is much, much wider than the rest. The second column is the
middle of the bunch when it comes to width and the last three columns
have the same width I think. Also, the button image is repeated when the
cell is bigger than the image itself but maybe there's no simple way
around that..The other problems I described I think are simple, I just
don't know how to fix them. I'm not really a C#-programmer and haven't
touched it for seven-eight months and it took quite a long time just to
get this far.

I can post the complete program if requested. Hope you understood my
explanation of how I want it to look. I can also post screenshots if needed.

Thanks for any replies!

- WP
Oct 27 '08 #1
0 4506

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sudha Pune | last post by:
Hi all i am using vs2005 C# window application i am trying to add the controls dynamically inside the "tablelayoutpanel", i need to add row by row and each row i will have to have 10 columns...
2
by: steve | last post by:
Hi All I need to change the rowspan, columnspan properties of a control when they are within a TableLayoutPanel (VB.net 2005) At runtime the property is not available, but is at design time ...
3
by: swartzbill2000 | last post by:
Hello, I have an array of Buttons down a column of a TableLayoutPanel. They all share a common click handler. In the handler, how can I determine the row of the TableLayoutPanel for the Button...
2
by: avanti | last post by:
Hi, I am trying to delete rows from a TableLayoutPanel at Runtime. I tried editing the RowStyles collection but doesn't do what I want it to. I have a table with 10 rows. I want to delete rows 2...
0
by: CodeChamp | last post by:
Hi, I am having a problem in my WinForm control which is a control derived from "ComboBox". Control adds a Text "Label" control in the parent control's collection when the control handle is...
0
by: Code Monkey | last post by:
I've got Windows Form which has a TableLayoutPanel on it. I'm dynamically adding Labels to the cells, binding their values from a DataTable. What I want to do, is if a certain value of the...
0
by: ponyryd | last post by:
It appears the default behavior for the final row/column is to autofill the "avaialble space" I set the number of rows and columns and then dynamically add my controls to each "cell". The...
0
by: strattonn | last post by:
I have a TableLayoutPanel on a form and I would like to freeze the first row and column so they do not scroll off the screen. Just like Excel's Fixed Row/Column feature. I have a feeling the...
4
by: Jeff | last post by:
Hello, I am trying to drag and drop a label control from one cell in a tablelayoutpanel to another (VB2005). There is no problem if both cells are visible, but i cannot get the tablelayoutpanel...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.