VB - Get RGB from Picturebox
In this tutorial I'll teach you how you can get the RGB code from the mouseposition on a picturebox.
You will need to make a new windows form application , call it GetPixel

Add a picturebox and a button on your form:

Change the picturebox propertie SizeMode to StretchImage:

Click the Picturebox once again and select the yellow events button in the properties windows and double click on the event MouseDown:

Then add the following codes:
- Private Sub PictureBox1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
- Dim mybmp As New System.Drawing.Bitmap(PictureBox1.Image)
- MessageBox.Show(mybmp.GetPixel(e.X, e.Y).ToString())
- End Sub
Go back to the design of your form and add a OpenFileDialog:

Double click the Load button on your form and add the following codes:
- Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
- OpenFileDialog1.ShowDialog()
- PictureBox1.ImageLocation = OpenFileDialog1.FileName
- End Sub
When you load an image and click on your picturebox you should get the RGB code from your mouseposition,
If you have a question, please leave a comment below !
Topic: VB - Get RGB from Picturebox
No comments found.
