473,586 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TableLayoutPane l 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 TableLayoutPane l to cover the entire client
area of my form. The TableLayoutPane l 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 TableLayoutPane l:
tblLayoutPanel. Dock = DockStyle.Fill;
tblLayoutPanel. CellBorderStyle = TableLayoutPane lCellBorderStyl e.Inset;
tblLayoutPanel. ColumnCount = 5;
tblLayoutPanel. RowCount = 2;
tblLayoutPanel. AutoSize = true;
tblLayoutPanel. ColumnStyles.Cl ear();
tblLayoutPanel. ColumnStyles.Ad d(new ColumnStyle(Siz eType.Percent, 20));
tblLayoutPanel. RowStyles.Clear ();
tblLayoutPanel. RowStyles.Add(n ew RowStyle(SizeTy pe.Percent, 50));

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

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

b.Anchor = AnchorStyles.Bo ttom | AnchorStyles.To p |
AnchorStyles.Le ft | AnchorStyles.Ri ght;

return b;
}

private Label CreateLabel(str ing initialText) {
Label l = new Label();

l.Text = initialText;
l.TextAlign = ContentAlignmen t.MiddleLeft;

l.Anchor = AnchorStyles.Bo ttom | AnchorStyles.To p |
AnchorStyles.Le ft | AnchorStyles.Ri ght;

return l;
}

With properties above I dont get the desired behavior, here's how it looks:
The TableLayoutPane l fills the entire client area of the form: Good.
The TableLayoutPane l 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 4521

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

Similar topics

2
11664
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 and each column i need to add one control If i try to do this the control coming one under one and not horizontaly, what is missing here,,,,
2
17546
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 Any ideas Regards
3
3071
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 that got clicked? Bill
2
30800
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 to 10 at runtime, keeping the first row unchanged. Can this be done? Thanks,
0
1617
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 created. Position and size of the control is evaluated on runtime and positioned properly in the parent control. The problem is, when i drop this...
0
844
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 DataTable meets a certain criteria, is change the background colour of the entire row of the TableLayoutPanel. What I'd like is something like...
0
4191
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 TableLayoutPanel is added to an Infragistics ultratabcontrol. The problem is no matter what I set for the tab or TableLayoutPanel size, the last row and...
0
1789
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 TableLayoutPanel does not support this natively. Is there a way to put a second TableLayoutPanel above the main panel with one row and have it scroll left and...
4
3629
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 to scroll in any direction (autoscroll is on), when the cell i want to drag to is no currently visible and requires scrolling to get to see it. ...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.