Good, I am glad you have decided not to cheat.
On the otherhand, reviewing someones code is the way most everyone learns.
Okay, as for the buttons, I assume you are using Visual Studio 2008 Express, if not get an IDE, SharpDev, Mono or VS2008e (all are free).
Here is some code to get you started:
Create a Windows application, and spread out the form so it can fit the 9 buttons along the bottom of the form.
For now, I dragged a Label component from the toolbox onto the center of the screen. This is the component we will drop the buttons onto. You will want to use your own target component(s) once you understand the concept. Set the AllowDrop property in the property editor of the label to true (means yes, I want this component to allow things to be dropped on it).
Select the first button (button1 in this case), and in the property editor, select the event (lightening bolt) tab, and find the onMouseMove event handler. Type in buttonMouseMove (or whatever you desire). Press enter and let it create the event handler code. Now go back to the form and select all of the other buttons, and drop down the onMouseMove property combobox, and select the buttonMouseMove handler you just created. This ties all of the buttons to the same event handler (just makes it easier than creating and duplicating 9 handlers).
Next you want to force the button into a Drag operation by using the button's DoDragDrop method. Now you have a button in the drag-able mode, lets deal with the label (the target for the drop operation).
As a minimum, you want to set the DragOver event handler of the label (target) so the user and component will know it is okay to drop the dragged object here. You will set the event handler for the DragOver of the lable to provide a drag effect which will change the cursor as the object is dragged over it.
Finally you want to assign an event handler to the DragDrop handler of the label to accept the dragged object.
In the handler you will get the object that has been dropped. We know this is a button for this little example, so I do not perform the typical checking and validation, but rather I just cast the incoming object as a Button, and set the Label's text to be the same as the dropped button.
Hope this helps,
// Jerry
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonMouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Button btn = sender as Button;
btn.DoDragDrop(sender, DragDropEffects.Copy);
}
}
private void label1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void label1_DragDrop(object sender, DragEventArgs e)
{
Button btn = e.Data.GetData(typeof(Button)) as Button;
label1.Text = btn.Text;
}
}
}