本文介绍了在winform中,标签可见性在闪烁状态下变为false。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我通过改变其前色和可见性以及定时器控制创建了一个闪烁标签。它适用于第一个tick事件调用,但是在多次调用之后,标签可见性会为某个调用获得连续的false值,并且其时间间隔也会减少并且快速闪烁。哪里是我无法察觉的问题。 请给我解决方案,让我知道问题出在哪里。 谢谢, 这是我的代码,可以更好地了解我的情况。 public partial class Form1:Form { protected System.Windows.Forms.Timer _timer; static int flaggg; private void Form1_Load( object sender,EventArgs e) { _timer = new System.Windows.Forms.Timer(); this ._ timer.Interval = 700 ; this ._ timer.Start(); this ._ timer.Tick + = new EventHandler(_timer_Tick); } public void _timer_Tick( object sender,EventArgs e) { this .lblmflash.Visible =!this .lblmflash.Visible; // this.lblmflash.Visible = true; lblmflash.ForeColor = Color.DarkGreen; if (flaggg == 1 ) { Appendlblmflash( 流程已完成,发送另一个缩进); flaggg = 0 ; } // this.lblmflash.Visible = false; } public void GetData() // 运行服务器// { string res = System.Text.Encoding.ASCII.GetString(temp); switch (res.Substring( 0 , 1 )) { case O: if (res.StartsWith( 输出)) { flaggg = 1 ; } break ; } } 私有 void dataGridView1_CellContentClick( object sender,DataGridViewCellEventArgs e) { Appendlblmflash( 缩进过程中!请等待......); } public void Appendlblmflash( string val) { if (InvokeRequired) { this .Invoke( new Action< string>(Appendlblmflash), new object [] {val}); return ; } lblmflash.Text = val; } } 解决方案 我建​​议以下解决问题: - 首先你创建自己的自定义标签(源自Label),其中包含其他属性,如SetBlink为布尔值,BlinkColor为Color。 - 这个新标签将Timer集成在其中 - 您不应该使用Visibility使其闪烁 - 更好的是将新的Color-Value(BlinkColor)设置为ForeColor(或BackColor或两者,如果您愿意)。为此,你必须覆盖ForeColor-Property以将其值重定向到内部变量。 - 现在如果SetBlink为true,你可以在ForeColor的两种颜色之间切换Timer-Method(否则返回保存的ForeColor-Value)。 如果这可能是一个解决方案,我会给你(如有必要)代码 - 例子如何实现。 I have created one blinking label by changing its forecolor and visibily properties and timer control. It works nice for the first tick event call but after more than one call the label visibility gets continuous false value for some call and its time interval also gets reduced and it blinking fast. where is the problem i cant detect. please give me solution and let me know where is the problem. thanks ,here is my code to understand my situation better.public partial class Form1 : Form { protected System.Windows.Forms.Timer _timer; static int flaggg; private void Form1_Load(object sender, EventArgs e) { _timer = new System.Windows.Forms.Timer(); this._timer.Interval = 700; this._timer.Start(); this._timer.Tick += new EventHandler(_timer_Tick); }public void _timer_Tick(object sender, EventArgs e) { this.lblmflash.Visible = !this.lblmflash.Visible; // this.lblmflash.Visible = true; lblmflash.ForeColor = Color.DarkGreen; if (flaggg == 1) { Appendlblmflash("Process completed, Send Another Indent"); flaggg = 0; } //this.lblmflash.Visible = false; } public void GetData() // to run server // { string res = System.Text.Encoding.ASCII.GetString(temp); switch (res.Substring(0, 1)) { case "O": if (res.StartsWith("OUTPROCESS")) { flaggg = 1; } break; } }private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { Appendlblmflash("Indent in process! Please wait..."); } public void Appendlblmflash(string val) { if (InvokeRequired) { this.Invoke(new Action<string>(Appendlblmflash), new object[] { val }); return; } lblmflash.Text = val; }} 解决方案 I would suggest the following to solve the Problem :- at 1st you create your own customized Label (which derives from Label) which has additional Properties like SetBlink as boolean and BlinkColor as Color.- this new Label integrates the Timer in it- you should not work with the Visibility to make it blinking - better you set a new Color-Value (BlinkColor) to the ForeColor (or BackColor or both if you prefer). For this you have to override the ForeColor-Property to redirect it's value to an internal variable.- now you could switch inside the Timer-Method between those both Colors for the ForeColor if SetBlink is true (else return to the saved ForeColor-Value).If this could be a Solution for you I would give you (if necessary) Code-Examples how to realise that. 这篇关于在winform中,标签可见性在闪烁状态下变为false。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-21 00:48