473,788 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DrawLine in a PictureBox

I'm using this to draw rectangles in a PictureBox image. Not all of the
rectangles are complete, and after drawing several, some of them start
disapearing. What's the reason for this?
Pen selPen = new Pen(Color.White );
Graphics graphic = this.PicBox.Cre ateGraphics();

............... ...
Point coord1 = new Point(x0, y0);
Point coord2 = new Point(x0, y);
Point coord3 = new Point(x, y0);
Point coord4 = new Point(x, y);

graphic.DrawLin e(selPen, coord1, coord2);
graphic.DrawLin e(selPen, coord1, coord3);
graphic.DrawLin e(selPen, coord2, coord4);
graphic.DrawLin e(selPen, coord3, coord4);
Nov 16 '05 #1
4 41410
"Jon Cosby" <jc****@nospam. net> wrote:
I'm using this to draw rectangles in a PictureBox
image. Not all of the rectangles are complete, and
after drawing several, some of them start
disapearing. What's the reason for this?


Unless you draw your graphics in response to a Paint event, they won't be
updated with the rest of the form. You can see this effect by dragging
another window over your window. Try something like this instead:

private void MyPictureBox_Pa int(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;

using Pen selPen = new Pen(Color.White )
{
// do your drawing here
}
}

PictureBox is not necessarily the best control to use, as this page
explains:
http://www.bobpowell.net/picturebox.htm

P.
Nov 16 '05 #2
Bitmap bitmap = new Bitmap(100, 100);
Graphics graphic = Graphics.FromIm age(bitmap);

......

Bitmap bitmap = new Bitmap(pb.Size. Width,pb.Size.H eight );

pb.Image=bitmap ;

or :

class MyPictureBox:Pi ctureBox

{

protected override void OnPaint(PaintEv entArgs e)

{

Graphics graphic = e.Graphics;

......

}

}

Regards,

Krzemo.

Użytkownik "Jon Cosby" <jc****@nospam. net> napisał w wiadomości
news:Zv******** *********@newsr ead1.news.pas.e arthlink.net...
I'm using this to draw rectangles in a PictureBox image. Not all of the
rectangles are complete, and after drawing several, some of them start
disapearing. What's the reason for this?
Pen selPen = new Pen(Color.White );
Graphics graphic = this.PicBox.Cre ateGraphics();

............... ...
Point coord1 = new Point(x0, y0);
Point coord2 = new Point(x0, y);
Point coord3 = new Point(x, y0);
Point coord4 = new Point(x, y);

graphic.DrawLin e(selPen, coord1, coord2);
graphic.DrawLin e(selPen, coord1, coord3);
graphic.DrawLin e(selPen, coord2, coord4);
graphic.DrawLin e(selPen, coord3, coord4);

Nov 16 '05 #3
This works for Windows bitmaps and jpeg, but it doesn't like the formatting
of gif files. Is there a way to reset this?
imgFile = this.GetImageDi alog.FileName.T oString();
MyBitmap = new Bitmap(imgFile) ;

graphic = Graphics.FromIm age(MyBitmap); // A Graphics object cannot be
created from
//
an image that has an indexed pixel format.
"Krzemo" <pk****@ka.onet .pl> wrote in message
news:c6******** **@news.onet.pl ...
Bitmap bitmap = new Bitmap(100, 100);
Graphics graphic = Graphics.FromIm age(bitmap);

.....

Bitmap bitmap = new Bitmap(pb.Size. Width,pb.Size.H eight );

pb.Image=bitmap ;

or :

class MyPictureBox:Pi ctureBox

{

protected override void OnPaint(PaintEv entArgs e)

{

Graphics graphic = e.Graphics;

.....

}

}

Regards,

Krzemo.

Użytkownik "Jon Cosby" <jc****@nospam. net> napisał w wiadomości
news:Zv******** *********@newsr ead1.news.pas.e arthlink.net...
I'm using this to draw rectangles in a PictureBox image. Not all of the
rectangles are complete, and after drawing several, some of them start
disapearing. What's the reason for this?
Pen selPen = new Pen(Color.White );
Graphics graphic = this.PicBox.Cre ateGraphics();

............... ...
Point coord1 = new Point(x0, y0);
Point coord2 = new Point(x0, y);
Point coord3 = new Point(x, y0);
Point coord4 = new Point(x, y);

graphic.DrawLin e(selPen, coord1, coord2);
graphic.DrawLin e(selPen, coord1, coord3);
graphic.DrawLin e(selPen, coord2, coord4);
graphic.DrawLin e(selPen, coord3, coord4);


Nov 16 '05 #4
Maybe something like this:

Bitmap bitmap = new Bitmap(pb.Size. Width,pb.Size.H eight );
MyBitmap = new Bitmap(imgFile) ;
graphic = Graphics.FromIm age(bitmap);
graphic.DrawIma geUnscaled(MyBi tmap ,0,0,pb.Size.Wi dth,pb.Size.Hei ght ) ;
//draw gif image on bitmap
pb.Image=bitmap ;
Regards,
Krzemo.

Użytkownik "Jon Cosby" <jc****@nospam. net> napisał w wiadomości
news:bB******** *********@newsr ead1.news.pas.e arthlink.net...
This works for Windows bitmaps and jpeg, but it doesn't like the formatting of gif files. Is there a way to reset this?
imgFile = this.GetImageDi alog.FileName.T oString();
MyBitmap = new Bitmap(imgFile) ;

graphic = Graphics.FromIm age(MyBitmap); // A Graphics object cannot be created from
//
an image that has an indexed pixel format.
"Krzemo" <pk****@ka.onet .pl> wrote in message
news:c6******** **@news.onet.pl ...
Bitmap bitmap = new Bitmap(100, 100);
Graphics graphic = Graphics.FromIm age(bitmap);

.....

Bitmap bitmap = new Bitmap(pb.Size. Width,pb.Size.H eight );

pb.Image=bitmap ;

or :

class MyPictureBox:Pi ctureBox

{

protected override void OnPaint(PaintEv entArgs e)

{

Graphics graphic = e.Graphics;

.....

}

}

Regards,

Krzemo.

Użytkownik "Jon Cosby" <jc****@nospam. net> napisał w wiadomości
news:Zv******** *********@newsr ead1.news.pas.e arthlink.net...
I'm using this to draw rectangles in a PictureBox image. Not all of the rectangles are complete, and after drawing several, some of them start
disapearing. What's the reason for this?
Pen selPen = new Pen(Color.White );
Graphics graphic = this.PicBox.Cre ateGraphics();

............... ...
Point coord1 = new Point(x0, y0);
Point coord2 = new Point(x0, y);
Point coord3 = new Point(x, y0);
Point coord4 = new Point(x, y);

graphic.DrawLin e(selPen, coord1, coord2);
graphic.DrawLin e(selPen, coord1, coord3);
graphic.DrawLin e(selPen, coord2, coord4);
graphic.DrawLin e(selPen, coord3, coord4);



Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7520
by: Dr. Zharkov | last post by:
Hello. I converted the project from VB6 in VB .NET 2003, however in the following two procedures there are errors (in Help of VB .NET 2003 it is not written, how to correct these errors): ' Plot the level curve F(X, Y) = level. Private Sub PlotLevelCurve(ByVal pic As System.Windows.Forms.PictureBox, _ ByVal level As Single, ByVal xmin As Single, ByVal xmax As Single, _ ByVal ymin As Single, ByVal ymax As Single, Optional ByRef step_size...
0
3884
by: akh | last post by:
I want to use de Drag and Drop ´s event to move a picture box from a form and within a Picture Box. But I have behaviour if the MyPBox As PictureBox as the Globale varible or not Thanks for your help, Here is the code.
2
3061
by: John | last post by:
I created a number of pictureboxes in a panel, and want to draw lines in those pictureboxes but I cannot. Please see the following code and make corrections. Thanks. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Panel1.AutoScroll = True Panel1.Width = 200 Panel1.Height = 200
2
10341
by: kalp suth via DotNetMonster.com | last post by:
I want to create arrows using lines on a picture in the picture box. On clicking the button "btnShowAll", the image is loaded and the lines drawn. "RGSShowAll()" calls "DrawObjs()" which does the actual drawing work. But after displaying all the arrows in a flick, the arrows disappers. I have debugged and came to know that the "Paint" event of the picturebox is refreshing the image, so the work done on the CreateGraphics created object is...
8
2401
by: Lou | last post by:
I have a picture box with an image loaded into it from an Image list (Its a solid Black Image). Next I draw some lines into the picture box. The resulting image with the lines is NOT the return value of PictureBox1.Image???? In the exapmle below control "D" shows only the picture(Black Image) without the lines I added using the brush? The Picturebox shows the lines nicely but the lines don't seem to be part of the controls "Inage"...
4
10235
by: Yash | last post by:
Have used DrawLine() method to draw some lines in the picturebox (sort of a barcode) in the picturebox paint event. This diagram has to be saved as an image in bmp or tiff format. But the problem is that these lines are not recognized as the image of the picturebox. It shows picturebox.image = nothing. How do we convert these lines drawn as the image of the picturebox so that it can be saved.
1
13045
by: motiee | last post by:
I'm having a problem with drawing on picturebox in vb.net programing. I draw line(or another shape's) on picturebox, anytime screen refreshes(open dialogbox ro menu,...) the drawn line on picturebox disapears. Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown x1 = e.Location.X y1 = e.Location.Y End Sub Private Sub PictureBox1_MouseUp(ByVal sender As...
0
1223
by: swagatikasahoo | last post by:
how to display all lines if i will scroll the picturebox. hi, ok i m sending the code. ****************************************************** Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint eGraphics = e.Graphics TryToCreateRec(eGraphics) PictureBox1.Refresh() End Sub Public Sub TryToCreateRec(ByVal eGraphics As Graphics) Dim blackPen As New Pen(Color.White,...
0
3169
by: =?Utf-8?B?RG9jdG9y?= | last post by:
I am making an application that streams video from a web camera onto the client area of a PictureBox on a Windows CLR Form in MS Visual Studio 2005 (using C++). The streaming video works fine, and now I am trying to create an image overlay. I am assuming that the best way for me to do this is to create a second PictureBox that lays over the streaming video. I would then need to draw directly into the bitmap shown in the overlaying...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.