2013-07-24 42 views
0

我有一個秒錶,並想更新你開始了時代的日誌,並停止手錶秒錶,更新日誌窗口形式

是這樣的: enter image description here

正如你可以開始看到它是空的,首先使用它和一行使用數量和持續時間,並且您使用更多次數的行顯示出來。我一直在尋找方法來做到這一點,但我找不到任何東西,我只是想創建一個tablelayout面板,但我無法將數據放入其中。

任何想法如何做到這一點?

感謝,

布魯諾

回答

0

對不起,我忘了提我使用VB,我想aplying你的代碼,但不可能讓我的工作,但找到了解決辦法

我用一個列表視圖控制器,並配置它爲我需要的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) 

它的工作正常。

希望它可以幫助未來的人。

0

您可以使用FlowLayoutPanel,用你的電話號碼和持續時間自定義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; } 
     } 
    } 
}