Click here to Skip to main content
16,020,343 members
Home / Discussions / C#
   

C#

 
AnswerRe: SQL Server and C# Pin
Mycroft Holmes30-Nov-11 17:01
professionalMycroft Holmes30-Nov-11 17:01 
GeneralRe: SQL Server and C# Pin
john john mackey1-Dec-11 11:01
john john mackey1-Dec-11 11:01 
AnswerRe: SQL Server and C# Pin
BobJanova1-Dec-11 1:46
BobJanova1-Dec-11 1:46 
GeneralRe: SQL Server and C# Pin
john john mackey1-Dec-11 11:23
john john mackey1-Dec-11 11:23 
AnswerRe: SQL Server and C# Pin
jschell1-Dec-11 13:50
jschell1-Dec-11 13:50 
QuestionC# desktop controls Pin
classy_dog30-Nov-11 6:19
classy_dog30-Nov-11 6:19 
AnswerRe: C# desktop controls Pin
fjdiewornncalwe30-Nov-11 8:39
professionalfjdiewornncalwe30-Nov-11 8:39 
AnswerRe: C# desktop controls Pin
BillWoodruff30-Nov-11 14:22
professionalBillWoodruff30-Nov-11 14:22 
A good way to get familiar quickly with how Controls are added, moved, etc. in a container like TableLayoutPanel is to start a new project (we're assuming WinForms here).

Put a TableLayoutPanel on the Form, set up some rows and columns, drag and drop a Label into one cell, and a TextBox into the next cell on the same row you put the Label.

Then open the Designer.cs file, and observe how those controls are added to specific cells in the TableLayoutPanel:
C#
this.tableLayoutPanel1.Controls.Add(this.textBox1, 2, 1);
this.tableLayoutPanel1.Controls.Add(this.label1, 1, 1);
An interesting thing is that if you inspect the Controls you've added, you'll see Row and Column properties available in the Property Grid browser, but the Controls themselves are not "extended," i.e., do not expose these properties in code you write.

So how do you move the TextBox to the next cell right of its current location. Like this:
C#
private void MoveTextBox_Click(object sender, EventArgs e)
{
    var tbPosition = tableLayoutPanel1.GetPositionFromControl(textBox1);

    tbPosition.Column++;

    tableLayoutPanel1.SetCellPosition(textBox2, tbPosition);
}
This crude example is just to show the basic mechanism; for production code you'd want to write, I think, a generalized procedure with parameters that would include the Control to be moved, and either a fixed location to be moved to, or relative vertical and/or horizontal offsets, and you'd want to error check that you were not trying to move something outside the TableLayoutPanel cell-bounds (which does not throw an error if you do, by the way: the control just stays in the same place).

Another strategy would be to use the 'Remove method of the TableLayOut.Controls collection, and then insert them back in where you wished.
tableLayoutPanel1.Controls.Remove(textBox1);

tableLayoutPanel1.Controls.Add(textBox1,0,0);
If you are adding new Controls at run-time, you are, of course, going to need to keep references to those Controls if you wish to re-use them after removing them from your container.

good luck, Bill
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill


modified 30-Nov-11 20:36pm.

QuestionHow do I make Post Publish Tasks work? DLL is locked? Pin
KevonHoughton30-Nov-11 5:37
KevonHoughton30-Nov-11 5:37 
Questionrun sql script in C# Pin
jojoba201130-Nov-11 0:09
jojoba201130-Nov-11 0:09 
AnswerRe: run sql script in C# Pin
Pete O'Hanlon30-Nov-11 0:17
mvePete O'Hanlon30-Nov-11 0:17 
QuestionRe: run sql script in C# <code>new</code> Pin
jojoba201130-Nov-11 0:22
jojoba201130-Nov-11 0:22 
AnswerRe: run sql script in C# new Pin
Pete O'Hanlon30-Nov-11 0:38
mvePete O'Hanlon30-Nov-11 0:38 
QuestionRe: run sql script in C# new Pin
jojoba201130-Nov-11 0:47
jojoba201130-Nov-11 0:47 
AnswerRe: run sql script in C# new Pin
Pete O'Hanlon30-Nov-11 0:56
mvePete O'Hanlon30-Nov-11 0:56 
QuestionRe: run sql script in C# new Pin
jojoba201130-Nov-11 0:58
jojoba201130-Nov-11 0:58 
AnswerRe: run sql script in C# new Pin
Pete O'Hanlon30-Nov-11 1:00
mvePete O'Hanlon30-Nov-11 1:00 
QuestionRe: run sql script in C# new Pin
jojoba201130-Nov-11 1:02
jojoba201130-Nov-11 1:02 
AnswerRe: run sql script in C# new PinPopular
Pete O'Hanlon30-Nov-11 1:07
mvePete O'Hanlon30-Nov-11 1:07 
GeneralRe: run sql script in C# new Pin
jojoba201130-Nov-11 1:09
jojoba201130-Nov-11 1:09 
GeneralRe: run sql script in C# new Pin
Pete O'Hanlon30-Nov-11 1:14
mvePete O'Hanlon30-Nov-11 1:14 
QuestionRe: run sql script in C# new Pin
jojoba201130-Nov-11 17:54
jojoba201130-Nov-11 17:54 
AnswerRe: run sql script in C# new Pin
Dave Kreskowiak1-Dec-11 4:11
mveDave Kreskowiak1-Dec-11 4:11 
AnswerRe: run sql script in C# Pin
jschell30-Nov-11 10:16
jschell30-Nov-11 10:16 
QuestionMicrosoft Interop Word Winforms issue on CITRIX Pin
spankyleo12330-Nov-11 0:00
spankyleo12330-Nov-11 0:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.