Winforms 秒表,更新日志窗口窗体
我有一个秒表,想更新你开始和停止秒表的时间记录 大概是这样的: 正如您在开始时看到的,它是空的,首先使用它和一个带有use number和duration的行,然后您使用的次数越多,显示的行就越多。我已经找到了一些方法,但是我没有找到,我想创建一个tablelayoutpanel,但是我不能把数据放进去 你知道怎么做吗 谢谢 Bruno您可以使用自定义的Winforms 秒表,更新日志窗口窗体,winforms,visual-studio,Winforms,Visual Studio,我有一个秒表,想更新你开始和停止秒表的时间记录 大概是这样的: 正如您在开始时看到的,它是空的,首先使用它和一个带有use number和duration的行,然后您使用的次数越多,显示的行就越多。我已经找到了一些方法,但是我没有找到,我想创建一个tablelayoutpanel,但是我不能把数据放进去 你知道怎么做吗 谢谢 Bruno您可以使用自定义的UserControl作为编号和持续时间,您将需要UserControl,因为如果您告诉面板堆栈垂直,您将无法添加相邻项。你也没有提到你用哪种
UserControl
作为编号和持续时间,您将需要UserControl
,因为如果您告诉面板堆栈垂直,您将无法添加相邻项。你也没有提到你用哪种语言编程,所以我会给你一个C语言的例子:看看这是否给你一个想法
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
FlowLayoutPanel flp = new FlowLayoutPanel()
{ Width = 200,
Height = 200,
AutoScroll = true,
FlowDirection = FlowDirection.TopDown ,
Location = new Point(0,0),
WrapContents = false
};
Button btn = new Button() { Text = "Add",
Height = 30,
Width = 70,
Location = new Point(200, 200)
};
public Form1()
{
InitializeComponent();
this.Controls.Add(flp);
this.Controls.Add(btn);
btn.Click += new EventHandler(btn_Click);
}
void btn_Click(object sender, EventArgs e)
{
flp.Controls.Add(new myUserControl() { Number = "1",
Duration = "00:00:00"
});
}
}
public class myUserControl:UserControl
{
Label number = new Label(){ ForeColor = Color.Blue,
Font = new Font("Arial", 14),
AutoSize = true,
Location = new Point(0,0)
};
Label duration = new Label(){ ForeColor = Color.Red,
Font = new Font("Arial", 14),
AutoSize = true,
Location = new Point(24, 0)
};
public myUserControl()
{
this.Size = new Size(new Point(150, 24));
this.Controls.Add(number);
this.Controls.Add(duration);
}
public string Number
{
get { return number.Text; }
set { number.Text = value; }
}
public string Duration
{
get { return duration.Text; }
set { duration.Text = value; }
}
}
}
很抱歉,我忘了提到我使用的是VB,我试着应用你的代码,但没能让我工作,但a找到了一个解决方案 我使用了listview控制器,并将其配置为我需要的4列,然后单击停止按钮时,我输入代码:
newitem = New ListViewItem
newitem.Text = pausa
newitem.SubItems.Add(inicio.ToLongTimeString)
newitem.SubItems.Add(fim.ToLongTimeString)
newitem.SubItems.Add(diferença.ToString.Substring(0, 8))
ListView1.Items.Add(newitem)
它工作得很好
希望将来能对别人有所帮助