(C#)表布局面板导致奇怪的输出

时间:2016-03-12 12:01:14

标签: c# winforms visual-studio chat

我正在尝试使用以下代码进行图形聊天,例如

private void Form1_Load(object sender, EventArgs e)
    {

        LogLoader();
        cellNo +=1;
        dateLoader(DateTime.Today.ToString("dd MMMM yyyy"));
        if (datestamp.Text == DateTime.Today.ToString("dd MMMM yyyy"))
        {
            dateLoader("Today");
        }
        tableLayoutPanel1.Controls.Add(datestamp, 0, cellNo);
        LogCreator();
        inputBubbleLoader("Hello... Testing this", DateTime.Now.AddDays(1).ToString("hh:mm:ss"));
        tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
        tableLayoutPanel1.Controls.Add(input,0,cellNo+1);
    }
    public void inputBubbleLoader(String inputText , String time)
    {
        Panel input = new Panel();

        inputLabel.Text = inputText;
        inputLabel.Font = new Font("Ariel", 10);
        Size size = TextRenderer.MeasureText(inputText,inputLabel.Font);
        inputLabel.Parent = input;
        inputLabel.Location = new Point(input.Location.X+5, input.Location.Y+5);
        timestamp1.Text = time;

        timestamp1.Parent = input;
        Size tsize = TextRenderer.MeasureText(timestamp1.Text, timestamp1.Font);
        timestamp1.Location = new Point(input.Location.X + input.Width - tsize.Width-5, input.Location.Y+input.Height-(tsize.Height)-5);

        inputLabel.MaximumSize = new Size(tableLayoutPanel1.Width, 0);
        input.AutoSize = true;
        inputLabel.AutoSize = true;
        timestamp1.AutoSize = true;
        cellNo += 1;
        tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
        tableLayoutPanel1.RowStyles[cellNo].Height = input.Height;
        tableLayoutPanel1.RowStyles[cellNo].SizeType = SizeType.AutoSize;
        tableLayoutPanel1.Controls.Add(input, 0, cellNo);
    }
    public void dateLoader(string date)
    {
        datestamp.Text = date;

        tableLayoutPanel1.RowStyles[cellNo].Height = datestamp.Height;
        tableLayoutPanel1.RowStyles[cellNo].SizeType = SizeType.AutoSize;
        tableLayoutPanel1.Controls.Add(datestamp,0,cellNo);
    }

    public void LogLoader()
    {

        string[] lines = File.ReadAllLines(@"C:\Users\Attey\Desktop\LogSave.txt");
        foreach(string line in lines)
        {
            if (String.IsNullOrWhiteSpace(line))
            {
                continue;
            }
            else if (line.StartsWith("--"))
            {
                dateLoader(line.Substring(line.IndexOf("-- [[")+1));
            }
            else if (line.StartsWith("["))
            {
                inputBubbleLoader(line.Substring(line.IndexOf(": ")), line.Substring(line.IndexOf("["), 8));

            }              
        }
    }
}

LogLoader不会加载书面邮件,只会加载测试邮件, 虽然程序成功写入文本文件。 每次运行程序时,表格布局都会有一些次要/重大更改

0 个答案:

没有答案