TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > C#(C Sharp)

Notices

Reply
 
Thread Tools Display Modes
Old 20-10-2007, 02:32 AM   #1
weird0
Guest
 
Posts: n/a
how to drag and drop an array of picturebox

I have been successful in making an array of picturebox and writing
event handlers for them, after hours of hard work. I want to drag and
drop all of the pictureboxes. And they dont.!!!! :-( Can somebody
help me this? What code should i write in the event handlers so that i
make all the picture boxes to drag and drop ?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace PicBoxApp
{
public partial class Form1 : Form
{


private System.Windows.Forms.PictureBox[] PicBoxes;


Rectangle dropRect = new Rectangle(180, 180, 60, 60);


private PictureBox myPictureBox;


public Form1()
{
InitializeComponent();
CenterToScreen();


PicBoxes = new System.Windows.Forms.PictureBox[8];


myPictureBox = new PictureBox();
myPictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
myPictureBox.Location = new System.Drawing.Point(64, 32);
myPictureBox.Size = new System.Drawing.Size(50, 50);
myPictureBox.Image = new Bitmap(@"D:\Documents and
Settings
\All Users\Documents\My Pictures\Sample Pictures\winter.jpg");
//myPictureBox.MouseDown += new
MouseEventHandler(myPictureBox_MouseDown);
//myPictureBox.MouseUp += new
MouseEventHandler(myPictureBox_MouseUp);
//myPictureBox.MouseMove += new
MouseEventHandler(myPictureBox_MouseMove);
//myPictureBox.Cursor = Cursors.Hand;


//initialise each picture box
for (i = 0; i < NodesLimit; i++)
{
//allocate the picture box
PicBoxes[i] = new PictureBox();
PicBoxes[i].Name = i.ToString();
//set up the initial properties
PicBoxes[i].Top = (i + 1) * 30;
PicBoxes[i].Left = (i + 1) * 20;
PicBoxes[i].Width = 150;
PicBoxes[i].Height = 100;
PicBoxes[i].SizeMode =
PictureBoxSizeMode.StretchImage;
PicBoxes[i].Image = Image.FromFile(@"D:\Documents and
Settings\All Users\Documents\My Pictures\Sample Pictures
\Winter.jpg");
//we are putting the index into the Tag property so
we
can access this like any other array
PicBoxes[i].Tag = i;
//Here we are wiring this picture boxes click to our
new common click handler.
PicBoxes[i].Click += new
System.EventHandler(ClickHandler);
PicBoxes[i].MouseDown += new
System.Windows.Forms.MouseEventHandler(MouseDown);
PicBoxes[i].MouseDown += new
System.Windows.Forms.MouseEventHandler(MouseUp);
PicBoxes[i].MouseDown += new
System.Windows.Forms.MouseEventHandler(MouseMove);
}
this.Controls.AddRange(PicBoxes);


Controls.Add(myPictureBox);
}


//This is the new click handling function for our array of
boxes
public void ClickHandler(Object sender, System.EventArgs e)
{

}


private void MouseDown(object sender, MouseEventArgs e)
{

}


private void MouseMove(object sender, MouseEventArgs e)
{


}


private void MouseUp(object sender, MouseEventArgs e)
{


}


private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{

}


}


}


Here are the links, where i took help:


http://pages.cpsc.ucalgary.ca/~carma...rp/controlarra...
http://www.java2s.com/Code/CSharp/GU...anddropthePict...


Need help
Regards

  Reply With Quote
Reply

Thread Tools
Display Modes




New To Site? Need Help?

All times are GMT +5.5. The time now is 03:10 PM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional