Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Visual Basic.Net How do you Draw Pixel onto PictureBox1?

This is really starting to piff me off now, no where on the internet is a working scrap of code that draws a single pixel onto a picture box based on x/y co-ordinates.

I would like to know if anyone has the programming knowledge on how do draw a pixel like this? :mystery:

EG: Draw(X,Y,R,G,B)
draws a single pixel on PictureBox1 at position X and Y with colour RGB

Please anyone with VB.net knowledge help me.

Thank you!!!
 
The Picturebox has a Paint method that uses the e.Graphics property.

You can do something like this:
Code:
 

    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

        e.Graphics.DrawLine(Pens.Black, 0, 0, 5, 5)

    End Sub

 
It makes a little line for you. All drawing onto controls is handled by the control's Paint sub.

Intellisense says this (basically):
Code:
DrawLine(<Pen Color>, <starting x>, <starting y>, <ending x>, <ending y>)
Experiment with that :)

EDIT:

You can even draw text directly:
Code:
e.Graphics.DrawString("String!", New Font("Arial", 8.5, FontStyle.Regular), Brushes.Red, 0, 0)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top