Graphics ... almost working ... missing one line?



I previously asked about two problems I had with some graphics - the first was that when I drew animation to a picturebox it wouldn't display when the Form loaded.

It was suggested to me by everyone that I stop using my own CreateGraphics calls, and override an OnPaint call to do this. As suggested, I created a custom control "drawBox" with an override on its OnPaint. Because I am using manual double buffering, as people suggested it was really just a matter of putting myBuffer.Render() into the OnPaint, and using drawBox.Invalidate as the call. In the end I only had to change/add about 8 lines of code, and its only taken about 16 hours to work out exactly which ones.

However, there is one annoying problem that remains. I can get it to show the initial screen just fine when it loads. But what I really want it to do is play the opening animation.

If I put the call to animate the screen

play_animation();

As the very last line of Form1_Load or anywhere else that I have tried, then the Form1 doesn't actually load and show anything until the animation is finished, at which point the Form pops up showing only the final (end) frame of the animation.

I had the same problem with the old (bad) way I did graphics, so I assume its not related ... but FWIW, here are they key parts of my new graphics:

public partial class Form1 : Form
{
static public drawBox pictureBoxn;

....

public class drawBox : Control
{
public drawBox()
{
this.Height = 600;
this.Width = 600;
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
myBuffer.Render();

}
}

I call the following in Form1_Load:

pictureBoxn = new drawBox();
currentContext = BufferedGraphicsManager.Current;
myBuffer = currentContext.Allocate(pictureBoxn.CreateGraphics(),
pictureBoxn.DisplayRectangle);
this.Controls.Add(pictureBoxn);

canvas = myBuffer.Graphics;
canvas.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
// canvas.Clear(Color.White);
screenwidth = pictureBoxn.Width;
screenheight = pictureBoxn.Height;
tracks = new Bitmap((int)screenwidth, (int)screenheight);
backgroundcanvas = Graphics.FromImage(tracks);
backgroundcanvas.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
backgroundcanvas.Clear(Color.Red);
pictureBoxn.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBoxn_Paint);

pictureBoxn.Refresh();
pictureBoxn.Show();
pictureBoxn.Update();
pictureBoxn.Invalidate();


.



Relevant Pages

  • Re: We need a new interface [warning; REALLY LONG]
    ... nethack does not live because of its graphics. ... Ascii mode (mainly because I am used to it, ... it could alarm you about monsters. ... Animation: Projectiles, Missiles, Spells, and the like ...
    (rec.games.roguelike.nethack)
  • Re: Pictures in incoming mail blocked
    ... > After I downloaded and installed SP2, my problem with blocked pictures is> only on the Yahoo group I belong to. ... Everyone's pictures or animations come> through as attachments, with a red X on the screen where the graphic should> be. ... I have to double click on the graphic and open it in one of my graphics> programs in order to see it or open the animation in my animation program. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: graphic identity in Windows XP Professional PPTX 2007
    ... Please tell us your PowerPoint version ... graphics when i go to the alt text tab. ... "Glen Millar" wrote: ... Finish by hitting That updates the animation pane.. ...
    (microsoft.public.powerpoint)
  • Re: Narration & Animation Timings
    ... Create new presentation with 1 blank slide ... Create custom animation settings for each graphic, ... the graphics end up appearing before I press the ... Jim Gordon MVP wrote: ...
    (microsoft.public.mac.office.powerpoint)
  • Re: R14sp3 and Mac OS X 10.4.2
    ... The graphics are indeed much slower ... problem with a similar 'lorenz attractor' animation. ... are run in matlab (i.e. - putting some plot function in a for loop, ... the 2D and 3D rendering tests that are slower than other machines. ...
    (comp.soft-sys.matlab)