Drawing a 1 pixel square

VPulse

Member
Joined
Jan 1, 2005
Messages
5
Programming Experience
3-5
Hello, I amazingly cannot draw a simple 1 pixel square in a picture box. How would I go about doing this?
 
You could use the System.Drawing.Graphics.FillRectangle GDI function.

If you want the image to be "permanent" use code similar to the following:
VB.NET:
'create a bitmap the size of the picturebox
Dim bmp As Bitmap = New Bitmap(PictureBox2.Width, PictureBox2.Height)
'create a graphics object from the bitmap
Dim g As Graphics = Graphics.FromImage(bmp)
'draw on the bitmap via the graphics object
'a black rectangle at location 10,10 of width and height=1
g.FillRectangle(Brushes.Black, 10, 10, 1, 1)
'set the image property of the picturebox to the bitmap
PictureBox2.Image = bmp
'clean up resources
g.Dispose()
 
Back
Top