CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2008
    Posts
    4

    Question Real-time picturebox painting (ie no Paint event)

    Ok.. is there a way to draw in realtime, without this Paint-event crap? I was thinking mainly in conjuction with timer ticks. I have googled and I didn't find anything.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    210

    Re: Real-time picturebox painting (ie no Paint event)

    it is not crap, it is feature you should use.

    Maybe your design is not good? Why you want not to use Paint Events?

    For Example:
    If you move your Window, your stuff must be redrawn -> It's is PaintEvent which does the work.
    If you resize your Window, your stuff must be redrawn -> It's is PaintEvent which does the work.

    Tip:
    Build your own methods drawing some stuff, where the Graphic argument (PaintEventArgs e) is passed to this method. Methods are called in OwnPaint then.

    Here is a simple code, which draws a line directly from OwnPaint,
    but this can be excluded into other methods:

    Code:
    namespace WindowsApplication1
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
    }
    
    protected override void OnPaint(PaintEventArgs e)
    {
    e.Graphics.DrawLine(new Pen(Brushes.Red, 6), 12, 20, 120, 200);
    }
    }
    }
    Use OnPaint, and you will not have to thin k about redrawing stuff....
    You can force a refresh/new painting everytime by this.Refresh();
    Last edited by MNovy; September 12th, 2008 at 07:26 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured