Drawing a single pixel

R

Rob T

This seems like a really stupid question, but here it goes........

is there a command to draw a single pixel?

The closest I can get is to draw a line that is 2 pixels wide, or do create
another image that's 1x1 with the color of the pixel, then do a DrawImage to
insert that image into the 'master' image...which seems like a huge waste!

Thanks.
 
H

Herfried K. Wagner [MVP]

Rob T said:
[Drawing a single pixel]

\\\
Private Sub Form1_Paint( _
ByVal sender As Object, _
ByVal e As PaintEventArgs _
) Handles MyBase.Paint
e.Graphics.FillRectangle( _
Brushes.Red, _
New Rectangle(100, 100, 1, 1) _
)
End Sub
///
 
B

Bob Powell [MVP]

What happens if the page units are set to inches? ;-)

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





Herfried K. Wagner said:
Rob T said:
[Drawing a single pixel]

\\\
Private Sub Form1_Paint( _
ByVal sender As Object, _
ByVal e As PaintEventArgs _
) Handles MyBase.Paint
e.Graphics.FillRectangle( _
Brushes.Red, _
New Rectangle(100, 100, 1, 1) _
)
End Sub
///
 
H

Herfried K. Wagner [MVP]

Bob,

Bob Powell said:
What happens if the page units are set to inches? ;-)

I read the article in your FAQ now and learned something new :).
 
R

Rob T

Good trick with the -1 for the pen width. Drawing the rectangle worked
fine. you still can't draw a line unless it's more than one pixel long:
objGraphics.DrawLine(New Pen(Color.Black, -1), New Point(5,5), New
Point(5,5)) Doesn't work.

No big deal if the FillRectangle works.......

Thanks guys!

BTW Bob. I adapted your c# graphics editor into a little VB app this week.
It's a bit different from yours now, I you had some good trick in yours that
I was able to adapt. Thanks!
 
B

Bob Powell [MVP]

Excellent. I love it when people use my code!


--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





Rob T said:
Good trick with the -1 for the pen width. Drawing the rectangle worked
fine. you still can't draw a line unless it's more than one pixel long:
objGraphics.DrawLine(New Pen(Color.Black, -1), New Point(5,5), New
Point(5,5)) Doesn't work.

No big deal if the FillRectangle works.......

Thanks guys!

BTW Bob. I adapted your c# graphics editor into a little VB app this
week. It's a bit different from yours now, I you had some good trick in
yours that I was able to adapt. Thanks!
 
S

Steve McLellan

How different the A-Team could have been if that had been Hannibal's
motto...

"> Excellent. I love it when people use my code!
 
R

Rob T

Careful....you're showing you age!

Steve McLellan said:
How different the A-Team could have been if that had been Hannibal's
motto...

"> Excellent. I love it when people use my code!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top