Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 641825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:06:16+00:00 2026-05-13T21:06:16+00:00

In C# WinForms – I am drawing a line chart in real-time that is

  • 0

In C# WinForms – I am drawing a line chart in real-time that is based on data received via serial port every 500 ms.

The e.Graphics.DrawLine logic is within the form’s OnPaint handler.

Once I receive the data from the serial port, I need to call something that causes the form to redraw so that the OnPaint handler is invoked. I have tried this.Refresh and this.Invalidate, and what happens is that I lose whatever had been drawn previously on the form.

Is there another way to achieve this without losing what has been drawn on your form?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:06:17+00:00Added an answer on May 13, 2026 at 9:06 pm

    The point is that you should think about storing your drawing data somewhere. As already said, a buffer bitmap is a solution. However, if you have not too much to draw, sometimes it is easier and better to store your drawing data in a variable or an array and redraw everything in the OnPaint event.

    Suppose you receive some point data that should be added to the chart. Firs of all you create a point List:

    List<Point> points = new List<Point>();
    

    Then each time you get a new point you add it to the list and refresh the form:

    points.Add(newPoint);
    this.Refresh();
    

    In the OnPaint event put the following code:

    private void Form_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.DrawLines(Pens.Red, points);
    }
    

    This works quite fast up to somehow 100 000 points and uses much less memory than the buffer bitmap solution. But you should decide which way to use according to the drawing complexity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Winforms you can say if ( DesignMode ) { // Do something that
WinForms databinding has very solid support for navigating related DataTables via DataRelation objects, but
Winforms .net 3.5 app. In my app I have a generic class that looks
WinForms, .NET 3.5 I have a ComboBox that needs to display a growing list
Winforms-How can I make dialog boxes appear centered on MainForm? That is as opposed
WinForms C#.. am getting some JSON in the format below (bottom of message) and
In WinForms, I can design a form and have a TabValue to control which
My WinForms application has a tab with a System.Windows.Forms.WebBrowser control. There are several controls
Our WinForms application has been reported to occasionally just close on its own. It
My WinForms app uses a number of BackgroundWorker objects to retrieve information from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.