Click here to Skip to main content
15,888,293 members
Home / Discussions / C#
   

C#

 
AnswerRe: How can I add two byte[1] + byte[2]? Pin
merh13-May-08 5:53
merh13-May-08 5:53 
Questionhow to make a service automatic Pin
prasadbuddhika13-May-08 2:59
prasadbuddhika13-May-08 2:59 
AnswerRe: how to make a service automatic Pin
dan!sh 13-May-08 3:02
professional dan!sh 13-May-08 3:02 
QuestionDisassmble GAC-installed assembly Pin
ctoma200513-May-08 2:45
ctoma200513-May-08 2:45 
QuestionFlicker Problem in GDI+ Pin
hdv21213-May-08 2:12
hdv21213-May-08 2:12 
AnswerRe: Flicker Problem in GDI+ Pin
Anthony Mushrow13-May-08 2:35
professionalAnthony Mushrow13-May-08 2:35 
GeneralRe: Flicker Problem in GDI+ Pin
hdv21213-May-08 5:58
hdv21213-May-08 5:58 
GeneralRe: Flicker Problem in GDI+ Pin
Anthony Mushrow13-May-08 6:07
professionalAnthony Mushrow13-May-08 6:07 
You need to put this.timer1.Start() somewhere else (like, wherever you had it before) and move this.panel1.Invalidate() into your timer.

Then, call your draw method from within the onPaint event:

private void panel1_Paint(object sender, PaintEventArgs e)
{
  this.Paint(e.Graphics, this.lastX, this.lastY);
}


Don't forget to remove this.Paint(...) from your timer.

int lastX;
int lastY;
bool reverse = false;
Pen pen = new Pen(Brushes.Red, 2);

public Form1()
{
  InitializeComponent();
  this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
  this.timer1.Start();
} 

private void panel1_Paint(object sender, PaintEventArgs e)
{
  this.Paint(e.Graphics, this.lastX, this.lastY);
}

private void Paint(Graphics g,int x,int y)
{
  g.Clear(Color.White);
  g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
  g.DrawEllipse(this.pen, new Rectangle(x, y, 100, 100));
  this.panel1.Invalidate();
}

private void timer1_Tick(object sender, EventArgs e)
{
  if (!this.reverse)
  {
    if ((this.lastX + 102) <= this.panel1.Width)
    {
      this.lastX += 2;
    }
    else
    {
      this.reverse = true;
    }
  }
  else
  {
    if (this.lastX >= 0)
    {
      this.lastX -= 2;
    }
    else
    {
      this.reverse = false;
    }
  }
  this.panel1.Invalidate();
}


My current favourite word is: Bacon!
-SK Genius

Game Programming articles start -here[^]-

GeneralRe: Flicker Problem in GDI+ Pin
hdv21213-May-08 6:17
hdv21213-May-08 6:17 
GeneralRe: Flicker Problem in GDI+ Pin
Anthony Mushrow13-May-08 6:18
professionalAnthony Mushrow13-May-08 6:18 
GeneralRe: Flicker Problem in GDI+ Pin
hdv21213-May-08 6:19
hdv21213-May-08 6:19 
GeneralRe: Flicker Problem in GDI+ Pin
Anthony Mushrow13-May-08 6:34
professionalAnthony Mushrow13-May-08 6:34 
GeneralRe: Flicker Problem in GDI+ Pin
hdv21213-May-08 6:42
hdv21213-May-08 6:42 
GeneralRe: Flicker Problem in GDI+ Pin
Anthony Mushrow13-May-08 6:50
professionalAnthony Mushrow13-May-08 6:50 
GeneralRe: Flicker Problem in GDI+ Pin
hdv21213-May-08 6:58
hdv21213-May-08 6:58 
AnswerRe: Flicker Problem in GDI+ Pin
Horacio N. Hdez.13-May-08 3:13
Horacio N. Hdez.13-May-08 3:13 
Questionmouse recognizer Pin
mehrnoosh13-May-08 1:50
mehrnoosh13-May-08 1:50 
AnswerRe: mouse recognizer Pin
Ashfield13-May-08 2:00
Ashfield13-May-08 2:00 
QuestionHow I know that a property is related to a xml file Pin
Guru Call13-May-08 1:29
Guru Call13-May-08 1:29 
QuestionTo Unzip the Files using C# Pin
senthilsstil13-May-08 0:57
senthilsstil13-May-08 0:57 
AnswerRe: To Unzip the Files using C# Pin
Spunky Coder13-May-08 1:06
Spunky Coder13-May-08 1:06 
GeneralRe: To Unzip the Files using C# Pin
dan!sh 13-May-08 1:18
professional dan!sh 13-May-08 1:18 
GeneralThis works fine for me Pin
dan!sh 13-May-08 1:24
professional dan!sh 13-May-08 1:24 
GeneralRe: This works fine for me Pin
Spunky Coder13-May-08 1:28
Spunky Coder13-May-08 1:28 
AnswerRe: To Unzip the Files using C# Pin
carbon_golem13-May-08 1:51
carbon_golem13-May-08 1:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.