Click here to Skip to main content
16,022,901 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have a small program
like you can see
it blinks too much
thanks for any help for this program so it will not blink
using System;
using System.Drawing;
using System.Windows.Forms;

namespace FlowOutString
{
    public partial class frmFlow : Form
    {
        string FineString = " ";
        Graphics g;
        PointF thispoint;
        Font thisFont = new Font("Times New Roman", 100);
        SolidBrush thisbrush = new SolidBrush(Color.Red);

        public frmFlow()
        {
            InitializeComponent();
        }

        private void frmFlow_Load(object sender, EventArgs e)
        {
            g = this.CreateGraphics();
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            FineString = "(-: Smile :-)";
            timer1.Interval = 25;
            g.Clear(BackColor);
            g.DrawString(FineString, thisFont, thisbrush, getPoint());
        }
        protected PointF getPoint()
        {
            thispoint.X -= 5;

            if (thispoint.X <= 0)
            {
                thispoint.X = this.Width;
            }
            thispoint.Y = 180;
            return thispoint;
        }
    }
}
Posted

1 solution

wrote:
g = this.CreateGraphics();


This is bad code. Don't do it. Handle the paint event instead


wrote:
g.Clear(BackColor);


This wipes the text, which means that it draws a blank area. Therefore, it flickers.

If you handle the paint event and call Invalidate() in your timer to fire it, that will help. You can also turn on double buffering.

this.SetStyle(

ControlStyles.AllPaintingInWmPaint |

ControlStyles.UserPaint |

ControlStyles.DoubleBuffer,true);


Will do that.

Not sure how this code will play with the awful use of CreateGraphics, so fix that first.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900