Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Trying to use the code below to define a new point. The code runs BUT the X and Y values in MyPosition are always 0. Using Label1 to check values, xPos and yPos are as expected and bmp.GetPixel(0, 0) does seem to read the color of point 0,0 on the screen.

Imports System.Drawing
Public Class Form1
Dim xPos As Integer
Dim yPos As Integer
Dim MyPosition As New Point(xPos, yPos)
    
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles Button1.Click


Using bmp As New Bitmap(1, 1)
      xPos = 130
      yPos = 100
      Using g As Graphics = Graphics.FromImage(bmp)
           g.CopyFromScreen(MyPosition, New Point(0, 0), New Size(1, 1))
      End Using
Label1.Text = "X = " & xPos & " Y = " & yPos & "  Color=" & bmp.GetPixel(0, 0).ToString
End Using

End Sub


Any thoughts will be well appreciated.
Thanks
Gary Vogel
Posted
Updated 18-Nov-10 5:25am
v2
Comments
Fredrik Bornander 18-Nov-10 11:25am    
Formatted code block.

Ummm... MyPosition never changes even though you change the xPos and yPos vairables. You have to create a NEW Point with the new values of xPos and yPos every time you execute this Click event handler.

Come to think of it, you don't even need MyPosition at all.

Using bmp As New Bitmap(1, 1)
      xPos = 130
      yPos = 100
      Using g As Graphics = Graphics.FromImage(bmp)
             g.CopyFromScreen(New Point(xPos, yPos), New Point(0, 0), New Size(1, 1))
      End Using
End Using
 
Share this answer
 
Comments
GaryV100 18-Nov-10 12:53pm    
Thanks again to all! That worked perfectly!!
I cannot see anywhere in your code that you initialize MyPosition to anything other than its default value. Until you do, it will remain at (0, 0).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900