更改和移动标签的值 [英] changing and moving of the value of the label

查看:58
本文介绍了更改和移动标签的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我想要一个带有计时器的标签值的更改或移动的代码或.DLL(每秒),
我想在表格上使用此标签,以便向我显示每种产品的最低库存,
如果有人有任何想法,请帮助我.
谢谢大家.:thumbsup:

hello
i want a code or .DLL of the changing and moving of the value of the label with timer(every second),
i want to use this label on my form so as to show me the minimum of the stock of every product,
please if somebody have any idea , help me.
thanks everybody.:thumbsup:

推荐答案

永远不要使用计时器System.Windows.Forms.Timer,尤其是在动画中(另请参见我对Piccadily的回答).最好使用System.Timers.Timer.但是,所有计时器都存在问题:您是否认为如果在触发新事件时代码仍然忙于计时器的事件句柄会发生什么情况?我知道,可以解决的问题仍然是不稳定的诱因.最好的方法是使用System.Threading.Thread.Sleep调用的线程.

精度不是大问题,因为标签的移动不能按事件的数量(不是固定的班次)进行,而是与实际经过的时间成比例(使用System.DateTime.Now测量).无法从非UI线程内控制UI.您应使用Control的Invoke方法的BeginInvokeSystem.Windows.Threading.Dispatcher. (实际上,与System.Timers.Timer相同.)

有关更多信息,请参见:调用: Control.Invoke()与Control.BeginInvoke( ) [ ^ ], Treeview扫描仪和MD5的问题 [ ^ ].

线程包装的有用代码和说明:如何传递ref参数 [
The timer System.Windows.Forms.Timer should never be used, especially in animation (see also my comments to the Answer by Piccadily). It''s better to use System.Timers.Timer. However, all timers are problematic: did you think what happens if the code is still busy with timer''s event handle when a new event is fired. Resolvable, I understand, still an invitation to instability. Best method is a thread with System.Threading.Thread.Sleep calls.

Accuracy is not a big problem as the move of the label can be done not per number of event (not fixed shift), but proportionally to the really elapsed time (measured using System.DateTime.Now). UI cannot be controlled from within the non-UI thread. You should use BeginInvoke of Invoke method of Control or System.Windows.Threading.Dispatcher. (Actually, same thing for System.Timers.Timer.)

See for more detail: Invocation: Control.Invoke() vs. Control.BeginInvoke()[^], Problem with Treeview Scanner And MD5[^].

Useful code and explanation for a thread wrapper: How to pass ref parameter to the thread[^].

A thread can be used in three ways: 1) a regular thread created by the constructor of System.Threading.Thread (see the reference on thread wrapper above); 2) a thread from a thread pool; 3) System.ComponentModel.BackgroundWorker.

—SA


Timer t;
        public fMain()
        {
            InitializeComponent();
            t = new Timer();
            t.Interval = 1000; // milliseconds
            t.Tick += new System.EventHandler(OnTimerEvent);
            t.Enabled = true;
            t.Start();
        }
        public static void OnTimerEvent(object source, EventArgs e)
        {
             // do what you like with your label ...
        }


这篇关于更改和移动标签的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆