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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:23:17+00:00 2026-05-22T15:23:17+00:00

I am drawing a line on a control on my Windows form like this:

  • 0

I am drawing a line on a control on my Windows form like this:

            // Get Graphics object from chart
            Graphics graph = e.ChartGraphics.Graphics;

            PointF point1 = PointF.Empty;
            PointF point2 = PointF.Empty;

            // Set Maximum and minimum points
            point1.X = -110;
            point1.Y = -110;
            point2.X = 122;
            point2.Y = 122;

            // Convert relative coordinates to absolute coordinates.
            point1 = e.ChartGraphics.GetAbsolutePoint(point1);
            point2 = e.ChartGraphics.GetAbsolutePoint(point2);

            // Draw connection line
            graph.DrawLine(new Pen(Color.Yellow, 3), point1, point2);

I would like to know if it is possible to draw a dashed (dotted) line instead of a regular solid line?

  • 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-22T15:23:18+00:00Added an answer on May 22, 2026 at 3:23 pm

    It’s pretty simple once you figure out the formatting that defines the dashes:

    float[] dashValues = { 5, 2, 15, 4 };
    Pen blackPen = new Pen(Color.Black, 5);
    blackPen.DashPattern = dashValues;
    e.Graphics.DrawLine(blackPen, new Point(5, 5), new Point(405, 5));
    

    The numbers in the float array represent dash lengths of different colors. So for a simple dash of 2 pixels on (black) and two off each your aray would look like: {2,2} The pattern then repeats. If you wanted 5-wide dashes with a space of 2 pixels you would use {5,2}

    In your code it would look like:

    // Get Graphics object from chart
    Graphics graph = e.ChartGraphics.Graphics;
    
    PointF point1 = PointF.Empty;
    PointF point2 = PointF.Empty;
    
    // Set Maximum and minimum points
    point1.X = -110;
    point1.Y = -110;
    point2.X = 122;
    point2.Y = 122;
    
    // Convert relative coordinates to absolute coordinates.
    point1 = e.ChartGraphics.GetAbsolutePoint(point1);
    point2 = e.ChartGraphics.GetAbsolutePoint(point2);
    
    // Draw (dashed) connection line
    float[] dashValues = { 4, 2 };
    Pen dashPen= new Pen(Color.Yellow, 3);
    dashPen.DashPattern = dashValues;
    graph.DrawLine(dashPen, point1, point2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm drawing a line using this code: this.graphics.moveTo(posx, posy); this.graphics.lineTo(2*posx,2*posy); But now I want
I'm developing a line drawing game, similar to Flight Control, Harbor Master, and others
I want to use core-plot for drawing line graph dynamically. data won't come at
In C# WinForms - I am drawing a line chart in real-time that is
Windows Forms: For System.Drawing there is a way to get the font height. Font
I have some XAML like this drawing a scatterplot of a time series (X-Axis:
I am having trouble drawing a line within a group box in a simple
What's the best practice for drawing a closed, filled path where each line has
Drawing a parallelgram is nicely supported with Graphics.DrawImage: Bitmap destImage = new Bitmap(srcImage.Width, srcImage.Height);
Drawing a blank on this, and google was not helpful. Want to make 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.