Click here to Skip to main content
15,118,172 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
i have a widows form in c#. what i want is to create an app that draw vertical line on a bitmap image. for that i wrote the following code:
private void Form1_Load(object sender, EventArgs e)
Bitmap bmOriginal = new Bitmap("kpk.bmp");
Rectangle cloneRect = new Rectangle(0,0 , 200, 200);
System.Drawing.Imaging.PixelFormat format =

Bitmap bmTile1 = bmOriginal.Clone(cloneRect, format);
pictureBox1.Image = bmTile1;

but when i run the app is does not show the lines on image.i tried to change the values in ractangle but it didnt effect. can somebody tells me what wrong and what i need to do.?or any other C# source for that....?
thanks in advance
Updated 9-Feb-12 22:00pm
Drawing on an image? Where?!
saifullahiit 10-Feb-12 3:02am
i m not drawing image. i want to draw lines on image.
And why?

That might have something to do with you not drawing any lines...
Try adding this:
Bitmap bmTile1 = bmOriginal.Clone(cloneRect, format);
using (Graphics g = Graphics.FromImage(bmTile1))
    g.DrawLine(Pens.White, 0, 0, 100, 100);
pictureBox1.Image = bmTile1;
saifullahiit 10-Feb-12 9:01am
it only draw one line. i want to draw 10 line. can you tell me how is it possible?
OriginalGriff 10-Feb-12 9:43am
You could call it ten times, with different values...
First of all, I don't see where are you drawing on the image.

You would draw if you did
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(myBitmap);


Besides, are you sure you need PictureBox. This control is often abused. It is only good if you put some static image in it, well, maybe change is on some event, but not for anything interactive, dynamic, animated, etc.

Please consider my advice where I'll show what to do instead.
Please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^].

See also:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^].


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