How to Get Pixel Color and Name from the Screen Using VB.Net

This tutorial is all about How to Get Pixel Color and Name from the Screen Using VB.Net. With this tutorial you can get Get Pixel Color and Name from the Screen Using VB.Net easily. So let’s get started:

  • First is open the Visual Basic, Select File on the menu, then click New and create a new project.

  • Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK

  • Then design your form like this just like what I’ve shown you below.
    Add a Picturebox, Textbox, and a Timer from the toolbox.
  • After that set the Time interval of Timer to 1 and set the Enable property of it to True in the Properties.
  • Double Click the Timer and add this following codes:
    [vbnet]Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim a As New Drawing.Bitmap(1, 1)
    Dim b As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(a)
    b.CopyFromScreen(New Drawing.Point(MousePosition.X, MousePosition.Y), New Drawing.Point(0, 0), a.Size)
    Dim c As Drawing.Color = a.GetPixel(0, 0)
    PictureBox1.BackColor = c
    TextBox1.Text = PictureBox1.BackColor.Name
    End Sub[/vbnet]
  • Click F5 to run the program and try to move around your mouse to see the results.
    Output:

If you have any comments or suggestion about on How to Get Pixel Color and Name from the Screen Using VB.Net, Please Feel Free to contact our webpage.

Download How to Get Pixel Color and Name from the Screen Using VB.Net Code Here

Other articles you might like to read:

1 thought on “How to Get Pixel Color and Name from the Screen Using VB.Net”

  1. Thanks for this. I have been doing this since the days of vb6 using the API call.
    Spent a great deal of time trying to figure out what is going on here and in the course of this I determined the following:

    b.CopyFromScreen(New Drawing.Point(MousePosition.X, MousePosition.Y), New Drawing.Point(0, 0), a.Size)
    can be written
    b.CopyFromScreen(MousePosition, New Drawing.Point(0, 0), a.Size)
    as the function require a point type for its first parameter and that is what MousePosition is.

Leave a Comment