Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to draw a line with rounded start and end point with drawline() method...

My code is -:

C#
using System;
using System.Drawing;
using System.Windows.Forms;

namespace ForPrintPre
{
    public partial class DigitalClockFriend : Form
    {
        Graphics grx;
        public DigitalClockFriend()
        {
            InitializeComponent();
        }        

        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
Comments
Sandeep Mewara 14-Feb-13 7:52am    
And... the issue is?
JayantaChatterjee 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

You need to put a LineCap[^] on the pen:
C#
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.
 
Share this answer
 
Comments
JayantaChatterjee 14-Feb-13 8:05am    
Thanks a lottttttttttt Sir.....
OriginalGriff 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900