Thread: Drag dot over grid

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    3

    Drag dot over grid

    Hi,

    I'd like to create an application with has a grid.
    On the grid is a dot which I want to be able to drag with my mouse (and later when the mouse thing works with a joystick).
    In a lable on the side I whant to put value's (0-255) for the x and y axis.
    Since I'm new to C# programming I don't have a clue on how to begin on it, I do have some experience with C++.

    The question is, how do I get the dot on the grid(which is in a piicturebox) how do I move it and how can I project the value in the labels(the picturebox is net 255 pixel high or long..)

    It should look like this: http://users.pandora.be/ymweb/grid2.jpg

    Best regards,
    Adam

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    My approach would be something like:

    Create a panel on the form
    Set the grid image as background image of the panel
    create a graphics object out of the panel
    on formload, draw a filled circle onto the panel using the graphics object acquired from the panel.
    Store the x,y coordinates of the filledcircle somewhere, now have an event like onMouseDown of the panel where you will check wether the x,y coordinates of the mouse are inside the circle's radius, if so , redraw the circle according to the mouse x,y coordinates as long as the mouse btn is down.

    Also let the circle only move the amount of pixels between each line of the grid , so it seems like its moving on the grid.

    Also have a onMouseUp event. When that event happens, let the circle for what it is ...

    That should work. I dont know wether there's a ready made solution built in C# for this, but this is how I would try and tackle this problem.

    ps: are you from Belgium , if so then you are probably the third belgian member on this board .

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    3
    hehe, yes I am from belgium.
    Thanks for the post, I'll try to work it out.
    More idea's are always welcome.
    If somebody finds an example code... feel free

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    3
    How excactly do I draw a circle in the panel because i can't find many examples of graphic objects in panels.

  5. #5
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    Create a panel called output ...

    then do

    Code:
    	public partial class Form1 : Form {
    
    		private Graphics g;
    
    		private int xCo=10;
    
    		private int yCo=10;
    
    		private int width = 10;
    
    		public Form1() {
    			InitializeComponent();
    			this.g = this.output.CreateGraphics();
    		}
    
    		private void output_Paint(object sender, PaintEventArgs e) {
    			g.FillEllipse(new SolidBrush(Color.Black), this.xCo, this.yCo, this.width, this.width);
    		}
    	}
    something like this....

    btw: im from belgium too ( East-Flanders ... the groovy side of Belgium , unlike that peasant West-Flanders...)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  2. More Windows Trouble
    By samGwilliam in forum Windows Programming
    Replies: 9
    Last Post: 04-12-2005, 10:02 AM
  3. Find a word in a 2d grid
    By The_Kingpin in forum C++ Programming
    Replies: 2
    Last Post: 02-24-2005, 05:38 PM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  5. Simple program i cant get (dot moving)
    By Lupusk9 in forum C++ Programming
    Replies: 4
    Last Post: 09-14-2004, 08:04 PM