Click here to Skip to main content
11,568,180 members (34,279 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# WinForm
I want to draw a line with rounded start and end point with drawline() method...

My code is -:

using System;
using System.Drawing;
using System.Windows.Forms;
namespace ForPrintPre
    public partial class DigitalClockFriend : Form
        Graphics grx;
        public DigitalClockFriend()
        private void button1_Click(object sender, EventArgs e)
            grx = this.CreateGraphics();
            grx.DrawLine(new Pen(Brushes.Black), 50, 50, 250, 50); 

Thanks in Advance!!!
Posted 14-Feb-13 1:48am
Sandeep Mewara at 14-Feb-13 7:52am
And... the issue is?
Jayanta Chatterjee at 14-Feb-13 8:01am
It's draw normal line(square start and end point)...
like some arc on start and end point....

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need to put a LineCap[^] on the pen:
private void myPanel_Paint(object sender, PaintEventArgs e)
    Graphics g = e.Graphics;
    Pen pen = new Pen(Brushes.Black, 20);
    pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
    g.DrawLine(pen, 50, 50, 100, 100);
Will draw a line with one round, and one square, end.
Jayanta Chatterjee at 14-Feb-13 8:05am
Thanks a lottttttttttt Sir.....
OriginalGriff at 14-Feb-13 8:14am
You are more than welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS

Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100