|
-
Dec 6th, 2006, 06:37 PM
#1
Thread Starter
Member
Help needed to dynamically add a button to a cell in a TableLayoutPanel:
Hello everybody,
I am trying to dynamically add a button to a TableLayoutPanel at a particular column and row location, but I don't seem to be having much luck so far.
The following code compiles, but I don't see anything on my form (Form1). Any help would be much appreciated in solving the problem.
What I would like to eventually have working is a routine that would use two arrays of integer values for the cell positions - (in conjunction with an array of Button objects) to determine where in the TableLayoutPanel my Button objects would be added.
Code:
//This is just a test to get the basics working first!!!
public Form1()
{
InitializeComponent();
Button MyButton = new Button();
MyButton.Visible = true;
TableLayoutPanel MyPanel = new TableLayoutPanel();
TableLayoutPanelCellPosition MyCellPosition = new TableLayoutPanelCellPosition();
MyCellPosition.Column = 1;
MyCellPosition.Row = 1;
MyPanel.SetCellPosition(MyButton, MyCellPosition);
}
Last edited by The Thing; Dec 6th, 2006 at 06:52 PM.
Using: VB.net + C#.net 2005 Express Editions + .Net Framework 2.0
~ Man Is The Warmest Place To Hide ~
-
Dec 6th, 2006, 06:54 PM
#2
Re: Help needed to dynamically add a button to a cell in a TableLayoutPanel:
SetCellPosition sets the cell position of a child control. If your Button is not a child coltrol the you can't set its cell position. You have to add the Button to the TLP before you can set its cell position:
Code:
MyPanel.Controls.Add(MyButton);
MyPanel.SetCellPosition(MyButton, MyCellPosition);
-
Dec 6th, 2006, 07:29 PM
#3
Thread Starter
Member
Re: Help needed to dynamically add a button to a cell in a TableLayoutPanel:
Thank you jmcilhinney, I was struggling with that for ages.
Previously I've coded a simple puzzle game in Java and I want to rewrite it now using Visual C#, but my coding skills are getting rusty for want of usage. For efficiency I need to be able to dynamically create and access the buttons that form part of my puzzle, hence the reason for my post.
Thanks again jmcilhinney, and happy Christmas to you and yours.
Using: VB.net + C#.net 2005 Express Editions + .Net Framework 2.0
~ Man Is The Warmest Place To Hide ~
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|