943,735 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 11862
  • C# RSS
Jan 9th, 2009
0

Drawing line in pictureBox

Expand Post »
Hi,

I have picture box with some image int it. I want to draw a line on the image. But when code executes, line is there but image is gone.
Here is the code:

bitmap bmp=new bitmap(pb.width,pb.height);
graphics g=new graphics.fromImage(bmp);
pen p=new pen(color.black,5);
g.drawLine(p,0,0,10,10);

Line is there, but underlaying image is gone. What should I do?

Pete
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
pete08 is offline Offline
32 posts
since Apr 2008
Jan 9th, 2009
0

Re: Drawing line in pictureBox

Because you need to paint it there each time the picture is painted most likely
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Jan 9th, 2009
0

Re: Drawing line in pictureBox

I'm working on application for WinMobile and there isn't OnPaint method there...
Reputation Points: 10
Solved Threads: 0
Light Poster
pete08 is offline Offline
32 posts
since Apr 2008
Jan 9th, 2009
0

Re: Drawing line in pictureBox

http://msdn.microsoft.com/en-us/libr...l.onpaint.aspx says there should be.

failing that, do a search for captureing from a paintbox/form and saving it as a bmp, so you update the bmp in memory.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Jan 9th, 2009
0

Re: Drawing line in pictureBox

Thanks, I have sorted it out.
Another question, do You have any idea how could I drag the image inside pictureBox instead of using scrollbars.
Reputation Points: 10
Solved Threads: 0
Light Poster
pete08 is offline Offline
32 posts
since Apr 2008
Jan 9th, 2009
0

Re: Drawing line in pictureBox

this was covered in another thread - you need to store the picture in memory, and then copy and show only in the picture box what the user is expecting to see
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Jan 9th, 2009
0

Re: Drawing line in pictureBox

Do You have some example code, plz
Reputation Points: 10
Solved Threads: 0
Light Poster
pete08 is offline Offline
32 posts
since Apr 2008
Jan 9th, 2009
0
Re: Drawing line in pictureBox
Hello,
Please tell me the some references about c#.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Durva is offline Offline
1 posts
since Jan 2009
Jan 9th, 2009
0

Re: Drawing line in pictureBox

Won't the drag and drop method for control work in WM?
Reputation Points: 11
Solved Threads: 4
Light Poster
hieuuk is offline Offline
44 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Cutting strings
Next Thread in C# Forum Timeline: logic of building a system where laods of people might be on at the same time.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC