如何在没有使用ASP.NET C#闪烁的情况下使用计时器? [英] How to use timer without flickering using ASP.NET C#?

查看:96
本文介绍了如何在没有使用ASP.NET C#闪烁的情况下使用计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在创建一个生日屏幕,我需要将Bday图像显示为背景,并在Bday日期显示员工详细信息...



因此所有细节将显示背景。但唯一的事情是每次定时器旋转时背景都会闪烁..

如何解决闪烁问题???



请做好我需要的事情团队......



Am creating a birthday screen where I need to display Bday images as background and also to display employee details on Bday date...

As a result all details with background will display. But the only thing is background flickers every time of timer rotation..
How to solve the flickering???

Please do the needful team...

Here is my Code:


        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    CompID = objGlobal.HRCompanyID;
                    BindNextImage();
                }
             

            }

            catch (Exception ex)
            {
               
            }
            return;


        }
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            BindNextImage();
        }


        public void BindNextImage()
        {
            try
            {
                ClearControls();
                Random _rand = new Random();
                dtData = objTvImage.getImage(CompID);
                int i = _rand.Next(0, dtData.Rows.Count);

                lblCompName.Text = dtData.Rows[i]["CompanyName"].ToString();
                lblDepName.Text = dtData.Rows[i]["Department"].ToString();
                lblEmpName.Text = dtData.Rows[i]["Name"].ToString();
                lblMonth.Text = dtData.Rows[i]["Designation"].ToString();
                lblDate.Text = dtData.Rows[i]["Date Of Birth"].ToString();
                GetImage((byte[])dtData.Rows[i]["Image"]);

                //To get templates

                if (lblDate.Text == "TRANSFER")
                {
                    pnlImage.BackImageUrl = "~/Images/" + "TRAN.jpg";
                }
                else if (lblDate.Text == "PROMOTED")
                {
                    pnlImage.BackImageUrl = "~/Images/" + "PRO.jpg";
                }
                else
                {
                    int day = (int)System.DateTime.Now.Day;
                    pnlImage.BackImageUrl = "~/Images/" + "BDay" + day.ToString() + ".jpg";
                }


            }

            catch (Exception ex)
            {
            }
        }

    }





我尝试过:



请参考上面的代码..



What I have tried:

Please refer the above code..

推荐答案

可能不是计时器本身,但你显示导致问题的数据的方式 - 没有看到你的代码,我们无法告诉你如何解决它。如果您在计时器中所做的只是使表单或面板失效,那么这可能会导致闪烁,因为背景被擦除并重新绘制,例如。



你可以通过将Form.DoubleBuffered属性设置为 true 来减少或消除问题,但我首先要查看用于在计时器时绘制内容的代码。碰巧。
Probably, it's not the timer itself, but the way you are displaying the data that is causing the problem - and without seeing your code we can't tell you what to do to fix it. If all you are doing in the timer is Invalidating the form or the panel, then that could cause the flicker as the background is erased and redrawn, for example.

You may be able to reduce or eliminate the problem by setting the Form.DoubleBuffered property to true, but I'd start by looking at teh code you use to draw things when the Timer.Tick happens.


这篇关于如何在没有使用ASP.NET C#闪烁的情况下使用计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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