使用C#和TableLayoutPanel创建时间轴

问题描述

我正在尝试创建带有tablelayoutpanel的时间轴,而且我快到了。我似乎无法弄清两件事。

  1. 首先,我想知道控件是否有任何方式可以跨半列(单元格)?
  2. 那我想知道如何在一个单元格中包含多个控件。

如果任何人都可以提供示例代码并附上说明,那就太好了。让我知道是否有任何不清楚的地方,或者是否需要发布更多代码

到目前为止,这是我的代码

    public void Init(List<DateModel> dates)
    {
        Table.Controls.Clear();
        Table.RowCount = 10;
        for (int i = 1; i <= Table.RowCount; i++)
            Table.RowStyles.Add(new RowStyle(SizeType.Percent,10));
        Table.ColumnCount = 38;
        for (int i = 1; i <= Table.ColumnCount; i++)
            Table.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
        Table.Dock = DockStyle.Fill;
        Controls.Add(Table);
        SetUpGrid();
        SetUp(dates);
    }

    public void SetUp(List<DateModel> dates)
    {
        var row = 1;
        foreach (var date in dates)
        {
            AddEntry(date.Day,row,1,Color.White,Color.Black,false);
            for (int i = 0; i < date.LogEntries.Count; i++)
                try
                {
                    AddEntry(string.Format("",GetColumnIndex(date.LogEntries[i].Start),GetColumnIndex(date.LogEntries[i].Stop)  date.LogEntries[i].Start,date.LogEntries[i].Start - date.LogEntries[i].Stop,false,date.LogEntries[i]);
                }
                catch (Exception)
                {
                    Console.WriteLine();
                }
            row++;
        }
    }

    private void AddEntry(string text,int row,int col,int columnSpan,Color foreColor,Color backColor,bool border,LogEntry entry = null)
    {
        var lbl = new Label
        {
            Text = text,AutoSize = false,AutoEllipsis = true,ForeColor = foreColor,BackColor = backColor,Dock = DockStyle.Fill,BorderStyle = border ? BorderStyle.FixedSingle : BorderStyle.None,TextAlign = ContentAlignment.MiddleLeft,Tag = entry,Cursor = Cursors.Hand
        };


        // Perhaps I need to check if a cell is empty? 


        lbl.Click += new EventHandler(EditEntry);            
        Table.Controls.Add(lbl,col,row);
        Table.SetColumnSpan(lbl,columnSpan);
    }

    public void SetUpGrid()
    {
        AddEntry(string.Format("Today:"),false);
        AddEntry("| 05:00",2,false);
        // And so on.. All the way to 23:00
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)