Bitmap/Graphic Moving
Bitmap/Graphic Moving
Bitmap/Graphic Moving
Bitmap/Graphic Moving
Bitmap/Graphic Moving
Bitmap/Graphic Moving Bitmap/Graphic Moving Bitmap/Graphic Moving Bitmap/Graphic Moving Bitmap/Graphic Moving Bitmap/Graphic Moving Bitmap/Graphic Moving Bitmap/Graphic Moving
Bitmap/Graphic Moving Bitmap/Graphic Moving
Bitmap/Graphic Moving
Go Back  Xtreme Visual Basic Talk > > > Bitmap/Graphic Moving


Reply
 
Thread Tools Display Modes
  #1  
Old 01-14-2008, 01:21 PM
AbuUmar AbuUmar is offline
Newcomer
 
Join Date: Oct 2007
Posts: 6
Default Bitmap/Graphic Moving


What I need is the following:

In the picture as I've uploaded you can see the mouse pointer and a white Pen,

Dim Tile_Rec As Graphics
Dim myPen As Pen = New Pen(Color.White, 1)
Tile_Rec = e.Graphics
Tile_Rec.DrawRectangle(myPen, kX - 16, kY - 16, 32, 32)


-MOUSE MOVEMENT-
kX = e.X
kY = e.Y
Map.Invalidate()

'Map is the picturebox that draws all those rectangle in 'Paint'.

But with my code, If I move the mouse the white rectangle will also move. I want to make that I can move the mouse inside that white rectangle (THE WHITE SQUARE SHOULD NOT MOVE), and if the mouse pointer leaves the bounds of the white rectangle, THEN ALSO the white rectangle should move to that way that the mouse pointer did leave the white rectangle.
Attached Images
File Type: jpg imgnd0.jpg (2.7 KB, 9 views)

Last edited by AbuUmar; 01-14-2008 at 01:45 PM.
Reply With Quote
  #2  
Old 01-14-2008, 05:33 PM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

Get the mouse location and with some mathematics determine which box should light up accordingly.
Reply With Quote
  #3  
Old 01-14-2008, 10:31 PM
AbuUmar AbuUmar is offline
Newcomer
 
Join Date: Oct 2007
Posts: 6
Default

And that would be how? I'm not that good at vb, I haven't worked with it so much. Could you help me out please?
Reply With Quote
  #4  
Old 01-16-2008, 04:50 AM
AbuUmar AbuUmar is offline
Newcomer
 
Join Date: Oct 2007
Posts: 6
Default

Is it really that hard? I thought that this code was easy and that someone over here would make it in a second.. but then I guess it must be kinda hard..
Reply With Quote
  #5  
Old 01-16-2008, 05:25 AM
cugone cugone is offline
Centurion
 
Join Date: Nov 2007
Posts: 160
Default

It's relatively simple, but we aren't just going to /give/ you the code. Part of the learning process is to try and figure it out with proper guidance.

As for an additional tidbit, an If statement to make sure the mouse is still inside the current rectangle would also be needed.
Reply With Quote
  #6  
Old 01-16-2008, 05:29 AM
AbuUmar AbuUmar is offline
Newcomer
 
Join Date: Oct 2007
Posts: 6
Default

What do you think I've been doing for hours?!
I'm making a mapeditor for a school project, times running.. I got 2 more days then time is up.
That's why I need this code.
Reply With Quote
  #7  
Old 01-16-2008, 07:47 AM
AtmaWeapon's Avatar
AtmaWeaponBitmap/Graphic Moving AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Ahh the days of putting off school projects until the last minute... in some ways, I miss it. If you look at the Posting Guidelines you agreed to when you created the account, you'll see several things. Two important things to note are that we won't do your homework for you and we aren't a code handout site. Another important thing is that the effort we put in is usually proportional to the effort you put in. You've described the problem well, and posted some code with no context (though you did put a lot of effort into syntax highlighting), but you don't seem very keen on having to think this problem through. I don't like that. If you don't like to think you are in the wrong class and you need to reconsider programming, it is arguably the hardest branch of mathematics.

It'd really be a tad easier to do this if each black square were a control; you could respond to the MouseEnter event by setting a "highlighted" flag, respond to the MouseLeave event by turning the flag off (don't forget to invalidate in both cases!), and in the Paint event handler choosing to draw or not draw the highlight based on this flag. This is precisely how the Button control draws its hover highlight when it is themed.

If you don't want to do that, it gets a bit more complicated. I assume you are drawing all of the tiles in some Paint event handler. Since you know the rectangle that bounds each tile, you can use the Rectangle.Contains method to determine if the mouse is inside of the rectangle... but wait, how do we get that position?

There is the System.Windows.Forms.Cursor.Position property, or the Control.MousePosition property, but be aware they give coordinates relative to the screen, not your form. You'll have to use the Control.PointToClient method to convert the mouse position to the coordinate system of the appropriate control.

Doing this for each tile is going to make your painting slower; you can optimize by first drawing all tiles, then calculating the one that has the highlight, then drawing the highlight. It's still a pain compared to using controls, though.
Reply With Quote
  #8  
Old 01-16-2008, 09:03 AM
AbuUmar AbuUmar is offline
Newcomer
 
Join Date: Oct 2007
Posts: 6
Default

Thanks a lot, I'll try to fix it now.

By the way, no I didn't wait until the last minute.
I've been spending more than 50h+ on this project, maybe more.
In that screenshot, you can only see the grid, not the mapeditor
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Bitmap/Graphic Moving
Bitmap/Graphic Moving
Bitmap/Graphic Moving Bitmap/Graphic Moving
Bitmap/Graphic Moving
Bitmap/Graphic Moving
Bitmap/Graphic Moving Bitmap/Graphic Moving Bitmap/Graphic Moving Bitmap/Graphic Moving Bitmap/Graphic Moving Bitmap/Graphic Moving Bitmap/Graphic Moving
Bitmap/Graphic Moving
Bitmap/Graphic Moving
 
Bitmap/Graphic Moving
Bitmap/Graphic Moving
 
-->