我想创建一个显示EPG的应用程序,如下图所示: http://gonedigital.net/wp-content/uploads/SonyEPG.jpg
我需要一个控件来显示时间轴。 我考虑使用datagridview,但我认为它不合适,因为不能为每一行设置列大小。 是否有可以使用的自定义cotrol? 如果没有关于如何开始的任何建议? 感谢
修改
我使用过TableLayoutPanel,它适用于少量数据。对于较大的数据,它变得太小了。 我搜索并发现SourceGrid非常快速和灵活。
答案 0 :(得分:2)
当然...尝试使用新表单的TableLayoutPanel示例。忽略颜色,因为它们是讨厌的;而是关注网格布局以及标签如何跨越列。这只是标题加上前三行。调整表单的宽度并注意比例如何保持:
public partial class Form1 : Form
{
private TableLayoutPanel grid = new TableLayoutPanel();
public Form1()
{
InitializeComponent();
grid.RowCount = 9;
for (int i = 1; i <= grid.RowCount; i++)
{
grid.RowStyles.Add(new RowStyle(SizeType.Percent, 42)); // all the same percent, the value doesn't matter
}
grid.ColumnCount = 16;
for (int i = 1; i <= grid.ColumnCount; i++)
{
grid.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 42)); // all the same percent, the value doesn't matter
}
grid.Dock = DockStyle.Fill;
this.Controls.Add(grid);
this.BackColor = Color.Black;
ExampleGrid();
}
private void ExampleGrid()
{
grid.Controls.Clear();
AddEntry("Today", 0, 1, 3, Color.White, Color.Black, false);
AddEntry("| 14:00", 0, 4, 3, Color.White, Color.Black, false);
AddEntry("| 14:30", 0, 7, 3, Color.White, Color.Black, false);
AddEntry("| 15:00", 0, 10, 3, Color.White, Color.Black, false);
AddEntry("| 15:30", 0, 13, 3, Color.White, Color.Black, false);
AddEntry("050", 1, 0, 1, Color.White, Color.Black, false);
AddEntry("BBC HD", 1, 1, 3, Color.White, Color.Black, false);
AddEntry("Mary Poppins", 1, 4, 8, Color.Black, Color.White, true);
AddEntry("Dustbin Baby -->", 1, 12, 4, Color.White, Color.LightGray, true);
AddEntry("051", 2, 0, 1, Color.White, Color.Black, false);
AddEntry("ITV1 HD", 2, 1, 3, Color.White, Color.Black, false);
AddEntry("Rosemary and Thyme", 2, 4, 6, Color.White, Color.Gray, true);
AddEntry("Agatha Christie's Poirot -->", 2, 10, 6, Color.White, Color.LightGray, true);
AddEntry("052", 3, 0, 1, Color.White, Color.Black, false);
AddEntry("Channel 4 HD", 3, 1, 3, Color.White, Color.Black, false);
AddEntry("The Green Berets", 3, 4, 5, Color.White, Color.Gray, true);
AddEntry("Coach Trip", 3, 9, 3, Color.White, Color.LightGray, true);
AddEntry("Countdown -->", 3, 12, 4, Color.White, Color.LightGray, true);
// ... etc ...
}
private void AddEntry(string text, int row, int col, int columnSpan, Color foreColor, Color backColor, bool border)
{
Label lbl = new Label();
lbl.Text = text;
lbl.AutoSize = false;
lbl.AutoEllipsis = true;
lbl.ForeColor = foreColor;
lbl.BackColor = backColor;
lbl.Dock = DockStyle.Fill;
lbl.BorderStyle = border ? BorderStyle.FixedSingle : BorderStyle.None;
lbl.TextAlign = ContentAlignment.MiddleLeft;
grid.Controls.Add(lbl, col, row);
grid.SetColumnSpan(lbl, columnSpan);
}
}