Click to See Complete Forum and Search --> : HELP: Moving controls at run time


WesTurrant
March 14th, 2007, 12:10 AM
I am making a card game and I need to move the cards around during run-time. Right now the design time effect is awesome!! I created to picture boxes to test with, and put a card in each picture box. I can move them around very smoothly and I even noticed that when one picture box gets close to another picture box in the designer it snaps into position ontop of the other picture box.

I don't know what makes this work, but is there anyway I can turn this feature on during run-time? I need some way to move my cards while the game is playing. I figured using picture boxes, and moving them around would be the best way.

darwen
March 14th, 2007, 03:39 AM
I don't know what makes this work, but is there anyway I can turn this feature on during run-time?


Nope.

Unfortunately you'll have to code this yourself. This is what programming is all about... writing code :D

You can handle the mouse down, mouse move and mouse up events on your form for you to be able to detect dragging. Then you'll have to move the controls yourself.

Darwen.

WesTurrant
March 14th, 2007, 11:55 AM
Done.

OK, please tell me how I can modify it to detect when the control being dragged is on top of another control. I need to know if the card is on top of the discard deck, another card, etc. I can't figure that part out.

Do I use the Drag Events?

Thanks.


bool Dragging;
int mousex;
int mousey;

private void textBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Dragging = true;
mousex = -e.X;
mousey = -e.Y;
int clipleft = this.PointToClient(MousePosition).X - textBox1.Location.X;
int cliptop = this.PointToClient(MousePosition).Y - textBox1.Location.Y;
int clipwidth = this.ClientSize.Width - (textBox1.Width - clipleft);
int clipheight = this.ClientSize.Height - (textBox1.Height - cliptop);
Cursor.Clip = this.RectangleToScreen(new Rectangle(clipleft, cliptop, clipwidth, clipheight));
textBox1.Invalidate();
}
}

private void textBox1_MouseMove(object sender, MouseEventArgs e)
{
if (Dragging)
{
Point MPosition = new Point();
MPosition = this.PointToClient(MousePosition);
MPosition.Offset(mousex, mousey);
textBox1.Location = MPosition;
}
}

private void textBox1_MouseUp(object sender, MouseEventArgs e)
{
if (Dragging)
{
Dragging = false;
Cursor.Clip = System.Drawing.Rectangle.Empty;
textBox1.Invalidate();
}
}

WesTurrant
March 14th, 2007, 12:40 PM
HAHAHAHA

I realized that since they would be playing against the computer, only in the first beta of the game. Until I get support for two players that the computer player would also need to move the cards around at run time. :eek::eek::eek::eek::eek::eek:

So I came up with this. :lol: Its got a small bug in this but its only testing. In a real game they will know where they are going. Here there just kind of drunk.


* A computer that needs to slide cards?
* Yes, a computer that needs to slide cards?
* A computer that slides cards, BRILLIANT!
* BRILLIANT!!