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 8243733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:36:56+00:00 2026-06-07T21:36:56+00:00

I am working on a project using .Net Compact Framework 3.5 using C# 3.0.

  • 0

I am working on a project using .Net Compact Framework 3.5 using C# 3.0.

I have a user control which receives data every 15 miliseconds and I have to draw shapes

like lines, rectangle, filled rectangles on user control.

I want to know what is the fastest way to draw these shapes, I am also open to use P/Invoke methods if there are some to increase performance and speed.

The code I am using is as follows:

     private void DrawThreeFunctions(Graphics g)
                {
                    // drawing back functions
                    if (DisplayFunction1.DrawOrder == DrawOrder.Back && GraphDataArray.Length > 0)
                    {
                        DrawFunction(g, DisplayFunction1, GraphDataArray[0]);
                    }
                    if (DisplayFunction2.DrawOrder == DrawOrder.Back && GraphDataArray.Length > 1)
                    {
                        DrawFunction(g, DisplayFunction2, GraphDataArray[1]);
                    }
                    if (DisplayFunction3.DrawOrder == DrawOrder.Back && GraphDataArray.Length > 2)
                    {
                        DrawFunction(g, DisplayFunction3, GraphDataArray[2]);
                    }
                    // drawing middle functions
                    if (DisplayFunction1.DrawOrder == DrawOrder.Middle && GraphDataArray.Length > 0)
                    {
                        DrawFunction(g, DisplayFunction1, GraphDataArray[0]);
                    }
                    if (DisplayFunction2.DrawOrder == DrawOrder.Middle && GraphDataArray.Length > 1)
                    {
                        DrawFunction(g, DisplayFunction2, GraphDataArray[1]);
                    }
                    if (DisplayFunction3.DrawOrder == DrawOrder.Middle && GraphDataArray.Length > 2)
                    {
                        DrawFunction(g, DisplayFunction3, GraphDataArray[2]);
                    }
                    // drawing front functions
                    if (DisplayFunction1.DrawOrder == DrawOrder.Front && GraphDataArray.Length > 0)
                    {
                        DrawFunction(g, DisplayFunction1, GraphDataArray[0]);
                    }
                    if (DisplayFunction2.DrawOrder == DrawOrder.Front && GraphDataArray.Length > 1)
                    {
                        DrawFunction(g, DisplayFunction2, GraphDataArray[1]);
                    }
                    if (DisplayFunction3.DrawOrder == DrawOrder.Front && GraphDataArray.Length > 2)
                    {
                        DrawFunction(g, DisplayFunction3, GraphDataArray[2]);
                    }
                } 


    private void DrawFunction(Graphics g, DisplayFunction function, int[] data)
            {
                Color color = Utils.GetColor(function.Color);
                switch (function.Shape)
                {
                    case FunctionShape.StepLine:
                        DrawStepLines(g, data, color);
                        break;
                    case FunctionShape.Rectangle:
                        DrawFilledRectangles(g, data, color);
                        break;
                    case FunctionShape.FramedRectangle:
                        DrawFramedRectangles(g, data, color);
                        break;
                    case FunctionShape.Line:
                        DrawLines(g, data, color);
                        break;
                    default:
                        break;
                }
            }

            #region Drawing methods
            // drawing lines
            private void DrawLines(Graphics g, int[] lineData, Color lineColor)
            {
                BarPositions = new List<int>();
                List<Point> linePoints = new List<Point>();
                int lineYPos = -1;
                int lineXPos = FirstBarDrawPosition;
                Point point = Point.Empty;

                using (Pen linePen = new Pen(lineColor, 2.0f))
                {
                    for (int i = FirstVisibleItemIndex, k = 0; i < _indexLimit; i++, k++)
                    {
                        if (base.GetBarEndPosition(k) > Width)
                            break;

                        lineXPos = GetTickPosition(k);
                        BarPositions.Add(lineXPos);

                        if (i < lineData.Length)
                            lineYPos = lineData[i];
                        else
                            continue;

                        point.X = lineXPos;
                        point.Y = lineYPos;

                        linePoints.Add(point);
                    }

                    if (linePoints.Any())
                    {
                        g.DrawLines(linePen, linePoints.ToArray());
                    }
                }
            }
            // drawing framed rectangles
            private void DrawFramedRectangles(Graphics g, int[] functionValues, Color functionColor)
            {
                BarPositions = new List<int>();

                int barXPos = FirstBarDrawPosition;
                Rectangle barRect = Rectangle.Empty;
                barRect.Width = WidthOfBar - 1;
                int barYPos = -1;

                using (Pen barPen = new Pen(functionColor))
                {
                    for (int i = FirstVisibleItemIndex, k = 0; i < _indexLimit; i++, k++)
                    {
                        if (base.GetBarEndPosition(k) > Width)
                            return;

                        BarPositions.Add(GetTickPosition(k));

                        if (i < functionValues.Length)
                            barYPos = functionValues[i];
                        else
                            continue;

                        //barRect = new Rectangle();
                        barRect.X = barXPos;
                        barRect.Y = barYPos;
                        //barRect.Width = WidthOfBar - 1;
                        barRect.Height = Height - barYPos;
                        g.DrawRectangle(barPen, barRect);
                        barXPos += (WidthOfBar + DistanceBetweenBars);
                    }
                }
            }
            // drawing filled rectangles
            private void DrawFilledRectangles(Graphics g, int[] functionValues, Color functionColor)
            {
                BarPositions = new List<int>();

                int barXPos = FirstBarDrawPosition;
                Rectangle barRect = Rectangle.Empty;
                barRect.Width = WidthOfBar;
                int barYPos = -1;

                using (SolidBrush barBrush = new SolidBrush(functionColor))
                {
                    for (int i = FirstVisibleItemIndex, k = 0; i < _indexLimit; i++, k++)
                    {
                        if (base.GetBarEndPosition(k) > Width)
                            return;

                        BarPositions.Add(GetTickPosition(k));

                        if (i < functionValues.Length)
                            barYPos = functionValues[i];
                        else
                            continue;

                        //barRect = new Rectangle();
                        barRect.X = barXPos;
                        barRect.Y = barYPos;
                        //barRect.Width = WidthOfBar;
                        barRect.Height = Height - barYPos;
                        g.FillRectangle(barBrush, barRect);
                        barXPos += (WidthOfBar + DistanceBetweenBars);
                    }
                }
            }

private void DrawStepLines(Graphics g, int[] lineData, Color lineColor)
        {
            BarPositions = new List<int>();
            int lineYPos = -1;
            int barXPos = FirstBarDrawPosition;

            using (Pen linePen = new Pen(lineColor, 2.0f))
            {
                for (int i = FirstVisibleItemIndex, k = 0; i < _indexLimit; i++, k++)
                {
                    if (base.GetBarEndPosition(k) > Width)
                        return;

                    BarPositions.Add(GetTickPosition(k));

                    if (i < lineData.Length)
                        lineYPos = lineData[i];
                    else
                        continue;

                    // draw third function line
                    //lineHeight = lineData[i];

                    g.DrawLine(linePen, barXPos, lineYPos, barXPos + WidthOfBar - 1, lineYPos);

                    barXPos += (WidthOfBar + DistanceBetweenBars);
                }
            }
        }

I am using drawing order and shape like step line , line , framed rectangle ( just rectangle ) and rectangle is filled rectangle.

Because of performance critical application I want to know the fastest way of drawing these shapes.

Thanks in advance for any suggestion.

  • 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-06-07T21:36:57+00:00Added an answer on June 7, 2026 at 9:36 pm

    Are you familiar with double-buffering? Keep an offscreen image buffer to do your writes to as the changes come in. Then override the OnPaint to blit the whole image in one statement. Also, override the OnPaintBackground with a no-op to get rid of the default behavior of clearing the control to its backcolor on each paint.


    Old as the hills, but here is an article on some best-practices on using GDI in the Compact Framework.

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

Sidebar

Related Questions

I'm working on a Web project using Asp.Net MVC, which I'll have to deploy
I'm working with an OCR project which is developed using Visual C++ on .net
I am using .NET Framework and C# and working on a large project. The
I am working on a project using .Net mvc. I have a csharp class
I am working on a c# project using ASP .net. I have a list
I am working on a project in C#.NET using the .NET framework version 3.5.
So, I'm working on a new project using ASP.NET MVC. Honestly I don't have
I am working on big ASP.NET project(we using ASP.NET 3.5) which comprised of 5
I have been working on a project for 6 months using net beans ide
I'm working on an ASP.NET web project using VS2010/C#, I have some text boxes

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.