Andrew
Andrew

Reputation: 552

How to draw a dot over pictureBox?

I have a form called Form2 which contains a picturebox1.

From a separate class file, I receive information from my pipe which are; charX, charY, map, mapX, & mapY.

If you view the picture I attached (right click and view larger), you can see that there is a mini-map to the map my character is in, which will also always show the movement of my character in the mini-map by displaying a yellow dot.

Now, there is a function in my Form2 which is called from my separate class file if my character entered a new map. What this function does is it updates my pictureBox1 imge-location to correspond with the correct mini-map in game. Pretty much it is an external mini-map from the game.

The problem is that it just displays the correct mini-map image, no character movement.

Now, here is a snippet of my code.

As you can read, if there is no mini-map in-game, there is no mini-map in my pictureBox (which comes from my server, 404 error); therefore, it sets the form size back to default (152,110) while displaying my error image. If there is a mini-map in-game, a function updates the picture in the pictureBox (by grabbing it off my server), then within the pictureBox1 code above, sets the Form size accordingly (to make it nice and tight, no extra space).

Now, what I want to accomplish is real time movement (which I will be using the charX&Y information provided by my pipe).

I want to draw a small yellow dot (like in the image provided) on-top of my pictureBox which will always be drawn accordingly to charX&Y.

The pictureBox on my form is always set to the location of 0,0.

My question is; How can I consistently draw a dot (using the charX&Y) over my pictureBox but using the location (I guess) of the form (ex: pictureBox location is at 0,0)?

Upvotes: 1

Views: 2228

Answers (1)

Poomrokc The 3years
Poomrokc The 3years

Reputation: 1099

I'm not much sure, but thanks to dotTutorials , he told me once to override the graphic

This may be confusing , but may work

    point a = new point(x,y);
    pen p = new pen(colour);
    Graphics g = Graphics.FromHwnd(Process.GetCurrentProcess.MainWindowHandle);
    g.drawline(p,a,a);

or you can use draw bitmap (bmp pictures) on the form

    int screen_width = 500;
    int screen_height = 500;

    // Your image..
    var crosshair_bitmap = (Bitmap)Image.FromFile("C:\Example\CrosshairImage.png");

    Graphics g = Graphics.FromHwnd(Process.GetCurrentProcesses.MainWindowHandle);
    g.DrawImage(crosshair_bitmap, new Point(x, y);

All credit to dotTutorials

Sorry for mistakes

Poom

Upvotes: 0

Related Questions