Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
GeneralRe: [c#]Place objects in tablelayoutpanel cells in specific order Pin
Member 1116046717-Oct-14 22:27
Member 1116046717-Oct-14 22:27 
GeneralRe: [c#]Place objects in tablelayoutpanel cells in specific order Pin
Richard MacCutchan18-Oct-14 4:02
mveRichard MacCutchan18-Oct-14 4:02 
GeneralRe: [c#]Place objects in tablelayoutpanel cells in specific order Pin
BillWoodruff17-Oct-14 21:39
professionalBillWoodruff17-Oct-14 21:39 
GeneralRe: [c#]Place objects in tablelayoutpanel cells in specific order Pin
BillWoodruff17-Oct-14 0:38
professionalBillWoodruff17-Oct-14 0:38 
GeneralRe: [c#]Place objects in tablelayoutpanel cells in specific order Pin
Richard MacCutchan17-Oct-14 2:15
mveRichard MacCutchan17-Oct-14 2:15 
GeneralRe: [c#]Place objects in tablelayoutpanel cells in specific order Pin
BillWoodruff17-Oct-14 2:45
professionalBillWoodruff17-Oct-14 2:45 
GeneralRe: [c#]Place objects in tablelayoutpanel cells in specific order Pin
Richard MacCutchan17-Oct-14 2:56
mveRichard MacCutchan17-Oct-14 2:56 
AnswerRe: [c#]Place objects in tablelayoutpanel cells in specific order Pin
BillWoodruff17-Oct-14 0:25
professionalBillWoodruff17-Oct-14 0:25 
I'm going to post some code "hints" here for how you can implement the alternate-row ascending/descending order labeling of the Cells, but I'd like to see you answer the following questions:
C#
What causes the apparently random order in which Cells are placed in the TableLayoutPanel in the first picture: your code ?

I was under the impression that you wanted the game to start with the Cells in random order: is that incorrect ?
If you need to restore the cell order shown in your second picture frequently, you may choose to create a "mapping" in advance of cell-content to cell-location, rather than map by computation each time you need that order re-created. For example (deliberately incomplete sketch):
C#
Dictionary<Point, string> cellMap = new Dictionary<Point, string>
{
    {new Point(0,6), "Start"},
    {new Point(5,0), "Final"},
    {new Point(0,0), "36"},
    // you fill in the rest
    {new Point(1,6), "1"},
};

// reset the initial layout:
private void ResetLayout()
{
    YourTableLayoutPanel.Controls.Clear();
    
    foreach (KeyValuePair<Point, string> kvp in cellMap)
    {
        Label lbl = new Label();
        lbl.AutoSize = false;
        lbl.Margin = new Padding(8);
        lbl.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
        lbl.TextAlign = ContentAlignment.MiddleRight;
        lbl.Text = kvp.Value;

        YourTableLayoutPanel.Controls.Add(lbl, kvp.Key.X, kvp.Key.Y);
    }
}
If you wish to create this layout by computation, then (deliberately incomplete example):
C#
List<Label> lblList = new List<Label>(); 

// assume you have initialized 'lblList with 42 Labels

private void orderLabels()
{
    int count = 0;

    Label cellLabel;

    for (int row = 0; row < 7; row++)
    {
        for (int col = 0; col < 6; col++)
        {
            cellLabel = lblList[count];

            if (count == 5)
            {
                cellLabel.Text = "Final";
                YourTableLayoutPanel.Controls.Add(cellLabel, 5, 0);
            }
            else if (count == 36)
            {
                cellLabel.Text = "Start";
                // for you to figure out
            }
            else
            {
                int offset;

                if (row%2 == 0)
                {
                    // ascending order
                    offset = (6 - row)*6 + col;
                }
                else
                {
                    // descending order
                    // offset = for you to figure out
                }

                cellLabel.Text = offset.ToString();
                YourTableLayoutPanel.Controls.Add(cellLabel, col, row);
            }         
            count++;
        } 
    }
}
Of course, there are other ways you can approach re-creating this initial state. If I were writing a game, I think I'd want to implement a general mechanism for saving and restoring the state of any game configuration; I'd probably create a "game-state" Class and serialize/de-serialize that to save/restore configuration.
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali


modified 17-Oct-14 8:42am.

QuestionPlay/Pause/Stop media through ASIO driver using C# Pin
Praveen Raghuvanshi16-Oct-14 18:16
professionalPraveen Raghuvanshi16-Oct-14 18:16 
AnswerRe: Play/Pause/Stop media through ASIO driver using C# Pin
Brisingr Aerowing17-Oct-14 10:08
professionalBrisingr Aerowing17-Oct-14 10:08 
GeneralRe: Play/Pause/Stop media through ASIO driver using C# Pin
Praveen Raghuvanshi26-Oct-14 7:37
professionalPraveen Raghuvanshi26-Oct-14 7:37 
Questionanother Func-enstein weirdness : and yet another bad example of MS documentation PinPopular
BillWoodruff16-Oct-14 11:38
professionalBillWoodruff16-Oct-14 11:38 
AnswerRe: another Func-enstein weirdness : and yet another bad example of MS documentation Pin
Gerry Schmitz16-Oct-14 17:43
mveGerry Schmitz16-Oct-14 17:43 
AnswerRe: another Func-enstein weirdness : and yet another bad example of MS documentation Pin
OriginalGriff16-Oct-14 19:27
mveOriginalGriff16-Oct-14 19:27 
AnswerRe: another Func-enstein weirdness : and yet another bad example of MS documentation Pin
Richard Deeming17-Oct-14 5:28
mveRichard Deeming17-Oct-14 5:28 
Questionnecessity to cast return value to nullable in lambda expression ? Pin
BillWoodruff16-Oct-14 7:25
professionalBillWoodruff16-Oct-14 7:25 
AnswerRe: necessity to cast return value to nullable in lambda expression ? Pin
Richard Deeming16-Oct-14 8:12
mveRichard Deeming16-Oct-14 8:12 
GeneralRe: necessity to cast return value to nullable in lambda expression ? Pin
BillWoodruff16-Oct-14 8:44
professionalBillWoodruff16-Oct-14 8:44 
GeneralRe: necessity to cast return value to nullable in lambda expression ? Pin
Richard Deeming16-Oct-14 8:49
mveRichard Deeming16-Oct-14 8:49 
AnswerRe: necessity to cast return value to nullable in lambda expression ? Pin
Pete O'Hanlon16-Oct-14 8:13
mvePete O'Hanlon16-Oct-14 8:13 
GeneralRe: necessity to cast return value to nullable in lambda expression ? Pin
BillWoodruff16-Oct-14 8:44
professionalBillWoodruff16-Oct-14 8:44 
QuestionHow to read tables in Excel Worksheet witc C# and XML Pin
Member 1110881716-Oct-14 3:13
Member 1110881716-Oct-14 3:13 
AnswerRe: How to read tables in Excel Worksheet witc C# and XML Pin
BillWoodruff16-Oct-14 5:25
professionalBillWoodruff16-Oct-14 5:25 
GeneralRe: How to read tables in Excel Worksheet witc C# and XML Pin
Member 1110881716-Oct-14 21:14
Member 1110881716-Oct-14 21:14 
AnswerRe: How to read tables in Excel Worksheet witc C# and XML Pin
Eddy Vluggen16-Oct-14 9:05
professionalEddy Vluggen16-Oct-14 9:05 

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.