每1秒刷新一次

时间:2015-10-23 13:57:31

标签: c# listview refresh windows-forms-designer

我设法让我的listview每隔2秒钟刷新一次,但它会像疯了一样闪烁,我怎么能解决这个问题?!

我想去试一下,猜测这是由于我如何刷新它。

Code1:

public partial class Skill_Tree : UserControl
{
    Skill_View ViewTree;

    public Skill_Tree()
    {
        InitializeComponent();
        SkillPanel();
        RefreshSkills();
    }

    private void RefreshSkills()
    {
        Timer timer123 = new Timer();
        timer123.Interval = 2000;
        timer123.Tick += new EventHandler(timer1_Tick);
        timer123.Start();

    }

    private void SkillPanel()
    {
        ViewTree = new Skill_View();
        ViewTree.Dock = DockStyle.None;
        panel2.Controls.Add(ViewTree);       
    }

    private void panel1_Paint(object sender, PaintEventArgs e)
    {
    }

    private void panel2_Paint(object sender, PaintEventArgs e)
    {
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        ViewTree.Dispose();
        SkillPanel();
    }
}

Code2:

    public Skill_View()
    {
        InitializeComponent();
        ListViewTrainingQue();

    }

    private void ListViewTrainingQue()
    {

        listView1.View = View.Details;
        listView1.GridLines = true;
        listView1.FullRowSelect = true;

        string string2 = "https://api.eveonline.com/char/SkillQueue.xml.aspx?keyID=4602486&&vCODE=BHGVeXQkRLKLkIkZQHdeyUxmUz9EfUwbvGzoc2eO4ZR8kRMYxk8PbD4LMwLF7BvH";



        // Add Columns to listview 
        listView1.Columns.Add("Name", 108);
        listView1.Columns.Add("Level", 100);
        listView1.Columns.Add("Remaing Time", 100);
        listView1.Columns.Add("Bar", 100);

       // string array1 = "2015-10-23 13:00";


        // Create Array to return values to. 
        string[] arr = new string[3];
        ListViewItem item;

       XmlDocument XMLtrans = new XmlDocument();
       XMLtrans.Load(string2);
       XmlNodeList TRnodelist = XMLtrans.SelectNodes("/eveapi/result/rowset/row");
        foreach (XmlNode xmlnode in TRnodelist)
        {
            string array1 = xmlnode.Attributes["endTime"].InnerText;
            var date = DateTime.Parse(array1);
            var Timespan = date - DateTime.Now;


            if (xmlnode.Attributes["typeID"] != null)
                arr[0] =  xmlnode.Attributes["typeID"].InnerText;
            if (xmlnode.Attributes["level"] != null)
                 arr[1] = xmlnode.Attributes["level"].InnerText;
            if (xmlnode.Attributes["endTime"] != null)
                arr[2] = string.Format("{0}h {1}m {2}s", Timespan.Hours, Timespan.Minutes, Timespan.Seconds);

            item = new ListViewItem(arr);
            listView1.Items.Add(item);
        }
    }

当前观点:

enter image description here

1 个答案:

答案 0 :(得分:0)

你试过这个吗?

private void ListViewTrainingQue()
{
    SuspendLayout();
    // do your updating code
    ResumeLayout();
    PerformLayout();
}