Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

How to draw a top line on a panel.


I would like to draw a line on the top edge of a panel.
I quess I need the onpain-event of the panel for that.
But I don't know how! And the line must have the color

Who knows the answer and is willing to help me?

Greetings, Peter Kiers
  • 2
  • 2
1 Solution
James AtkinSenior Principle Software EngineerCommented:
You need to add the Paint Event to the Panel using the Events Tab in its Properties

Then just add something like this in the Paint Handler...

        private void panel1_Paint(object sender, PaintEventArgs e)
            Pen p = new Pen(new SolidBrush(Color.FromArgb(0xC2, 0xC4, 0xCB)));
            e.Graphics.DrawLine(p, 1, 1, 100, 1);

Hope this helps...
peterkiersAuthor Commented:
It does not draw the whole line on the top edge of the panel.

peterkiersAuthor Commented:
I have change:

e.Graphics.Drawline(p, 1, 1, 176, 1);

Now the line is as wide a the panel width.

But when I resize the panel the line stays the same!!!
James AtkinSenior Principle Software EngineerCommented:
Just change the "176" to panel1.width
or whatever your panel is called
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now