Win Form, Image and getting the presice x,y Pixel the mouse is poi

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All,

Here is what I would like to do

I am creating a game program that displays a map (preferably in hexes but
that is another matter) and whenever the user is over the "map" I want to
know the x,y coords (in pixels) of where he is pointing to.

Here is what I have done

Place an Picturebox on a windows form

Assign a picture to the control

Is there an event on the picturebox control that fires whenever the mouse
moves along on the picture?

If I am trying to implement the wrong approach please let me know.

Thanks

p.s. side note -- if anyone can point me in the right direction for finding
a book that helps program games using VB I would much appreciate it.

Corey
 
There is a mousemove event that will tell you every time the user moves the
mouse, and you can get the x,y from that event. I think it will be relative
to the picturebox and not the form, but you'll have to look to see about
that.

Post any more questions you have... Happy to help.

Chris
 
Chris,

Thank you it worked, now all i have to do is figure out how to get a map of
the world that is an image and to get it to scroll left and right and up and
down automatically when you move the mouse near the top, bottom, left and
right of the map

And (LOL) i have to figure out a way to get this map image to work like a
cylinder (that means that i can continuously scroll left and right and it
will loop.

Lots to ask for i know, your help is much appreciated.

Again any pointers to websites, books etc that can show me how to do this
would be much appreciated.

Corey
 
Mousemove event on the picturebox control. Then use the mouseeventargs
object to locate your x or y coordinate.
 
Well what you are trying to do isn't too difficult. I'll lay out the
concepts and you let me know what you need more help with.

To figure out when to scroll right and left, this is the easy one. Let's
say your are going to put them in scroll mode when they hit withing 5% of
the edge of the picturebox. That just becomes LeftSide if the X coord is
<= (.05*PictureBox1.Width), RightSide if the X coord is >=
PictureBox1.Width - (.05*PictureBox1.Width) and so on for the top and
bottom.

Now for the scrollingi image, I think you are going to have to do some
picture manuplation. I've never done anything like this so maybe someone
else can talk about it. But, as you scroll left, you need to take the left
move Column of pixels and move them to the right side and slide all the
other pixels left one. I don't know which class you use to do this type of
thing. You may have to research the data format and do it raw in memory.

Anyone smarter than me have an idea about this?

Chris
 
Thanks Chris,

I had thought of that, thank you for confirming my hypothesis.

I figure that i will have to find some way of redrawing the image, or I
would have to have the image broken up into vertical 1 pixel slices and
manually draw them into my container as needed (so that each time I scrolled
left, I would get the vertical slice that was immediately to the left of the
currently displayed leftmost slice....

I must be blithering on at this point, there must be some tool or graphical
format(graphical tool) that will do this for me (like photoshop etc).

Corey
 
I believe that the format of a bitmap is pretty readily avaible. You should
be able to read the file into memory and then move the pieces around to
create a new bitmap. It might be the hard way to go about it, but it should
work. Do a google search for bitmap format, you'll find lots of sites that
talk about it.

Chris
 
Back
Top