Miyagi v1.2 TableLayoutPanel

wolen

10-12-2012 15:21:18

Hi, I have troubles with TableLayoutPanel (2 troubles). I want to make this layoutPanel with 2 column and some rows (could be more then 2). I tried this code and it works. BUT when I have 3 rows so I get exception...out of range. How it is possible?

TableLayoutPanel table = new TableLayoutPanel();
table.Location = new Point(300, 300);
table.Size = new Size(200, 200);
table.Skin = skinDict["Panel"];
table.RowCount = 2;
table.ColumnCount = 2;

// Make sure you create the TableLayoutStyle objects, and add them to the table's column styles and row styles
// (dont need to do this for flow layout)
var colStyless = new TableLayoutStyle[table.RowCount];
var rowStyless = new TableLayoutStyle[table.ColumnCount];

for (int i = 0; i < colStyless.Length; i++)
colStyless[i] = new TableLayoutStyle(SizeType.Absolute, 70); //width

for (int i = 0; i < rowStyless.Length; i++)
rowStyless[i] = new TableLayoutStyle(SizeType.Absolute, 40); //height

table.ColumnStyles.AddRange(colStyless);
table.RowStyles.AddRange(rowStyless);

for (int i = 0; i < table.RowCount; i++) {
for (int j = 0; j < table.ColumnCount; j++) {
Button b = new Button();
b.Size = new Size(50, 50);
b.Skin = skinDict["Button"];
table.AddControl(b, i, j);
}
}

gui.Controls.Add(table);


Second problem is scrollbars. I tried this code but scrollbar is still hidden.
table.HScrollBarStyle = new ScrollBarStyle
{
Extent = 16,
ThumbStyle =
{
BorderStyle =
{
Thickness = new Thickness(2, 2, 2, 2)
}
}
};
table.VScrollBarStyle = new ScrollBarStyle
{
Extent = 12,
ThumbStyle =
{
BorderStyle =
{
Thickness = new Thickness(2, 2, 2, 2)
}
}
};


It will be some stupid mistake but I want to solve mainly the first problem. I dont know how can be fisrt add to table.AddControl out of range.

any help would be appreciated =)

smiley80

10-12-2012 18:01:30

var colStyless = new TableLayoutStyle[table.RowCount];
var rowStyless = new TableLayoutStyle[table.ColumnCount];

should be:
var colStyless = new TableLayoutStyle[table.ColumnCount];
var rowStyless = new TableLayoutStyle[table.RowCount];


Scrollbars don't work properly with TableLayoutPanels at the moment (they should be visible though).

wolen

10-12-2012 18:30:13

Ou thanks, little mistake and I couldnt find it =).

So do you know about some alternative? Or better, what is working with them? I want to make little menu bar.

LayoutPanel with Material ... Count
Material ... Count
.
.
.
What can I use?

wolen

10-12-2012 18:32:16

When I thinking about it maybe I have mistake in skin file. What I must have in it for scrool bars? It must be declare in it, isnt it?

wolen

10-12-2012 22:14:37

Ok, if anyone has same problem here is my solution. I used Panel:
var materialBox = new Panel() {
Size = new Size(upperMenu.Width / 3, upperMenu.Height),
ResizeMode = ResizeModes.None,
Skin = skinDict["PanelSkin"],
Opacity = 0.5f,
TabStop = false,
TabIndex = 0,
Throwable = true,
ResizeThreshold = new Thickness(8),
BorderStyle = new BorderStyle { Thickness = new Thickness(2) },
HScrollBarStyle = new ScrollBarStyle() {
Extent = 16,
ThumbStyle = {
BorderStyle = {
Thickness = new Thickness(2, 2, 2, 2)
}
}
},
VScrollBarStyle = new ScrollBarStyle {
Extent = 12,
ShowButtons = true,
ThumbStyle = {
BorderStyle = {
Thickness = new Thickness(2, 2, 2, 2)
}
}
}

};


for (int i = 0; i < materials.Count; i++) {
materialList.Add(materials[i].name, new MaterialGUIPair(materials[i].name, 0, materialBox.Width,i));
}

int row = 0;
foreach (KeyValuePair<string, MaterialGUIPair> valuePair in materialList) {
materialBox.Controls.Add(valuePair.Value.name);
materialBox.Controls.Add(valuePair.Value.value);
row++;
}

upperMenu.Controls.Add(materialBox);


and

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Miyagi.UI.Controls;
using Miyagi.Common.Data;

namespace Strategy.GameGUI {
struct MaterialGUIPair {
public Label name;
public Label value;

public MaterialGUIPair(string nameString, int valueInt, int maxWidth, int position) {
int newWidth = maxWidth/5;
name = new Label() {
Size = new Size(newWidth*3, 25),
Text = nameString,
Location = new Point(0,position*26),
TextStyle = {
Alignment = Miyagi.Common.Alignment.MiddleLeft,
ForegroundColour = Colours.White
},
Padding = new Thickness(5, 1, 1, 1)
};
value = new Label() {
Size = new Size(newWidth, 25),
Text = valueInt.ToString(),
Location = new Point(30, position * 26),
TextStyle = {
Alignment = Miyagi.Common.Alignment.MiddleRight,
ForegroundColour = Colours.White
},
Padding = new Thickness(5,1,1,1)
};
}

public void update(int i) {
value.Text = i.ToString();
}
}
}