Hey,
For the image drag and drop stuff I ahve a little problem...I want it to drag and drop but I dont want it to totaly take the image out...So what I am trying to do is instead of making it so that when you drag and drop an image it goes that but the picturebox that you draged the image from will still have it's image in there...Here is the code:
private void pictureBox2_DragDrop(object sender, DragEventArgs e){
// Display the image in the selected PictureBox control. PictureBox pic = ((PictureBox)(sender));pic.Image = ((
Bitmap)(e.Data.GetData(DataFormats.Bitmap))); if ((e.KeyState & CtrlMask) != CtrlMask){
if (sender == pictureBox1){
pictureBox2.Image =
null;}
else{
pictureBox1.Image =
null;}
}
}
private void pictureBox2_DragEnter(object sender, DragEventArgs e){
if ((e.Data.GetDataPresent(DataFormats.Bitmap))){
if ((e.KeyState & CtrlMask) == CtrlMask){
e.Effect =
DragDropEffects.Copy;}
else{
e.Effect =
DragDropEffects.Move;}
}
else{
e.Effect =
DragDropEffects.None;}
}
private void pictureBox2_MouseDown(object sender, MouseEventArgs e){
if (e.Button == System.Windows.Forms.MouseButtons.Left){
PictureBox pic = ((PictureBox)(sender)); if (!(pic.Image == null)){
pic.DoDragDrop(pic.Image,
DragDropEffects.Move | DragDropEffects.Copy);}
}
}
Thanks :)

Drag and Drop problem(I have the code thoe)
Auris
no, it did the same thing as before....but I guess you are right about the ctrl key part, should I just make the code this to make it always do what I want:
{
// Display the image in the selected PictureBox control. PictureBox pic = ((PictureBox)(sender));pic.Image = ((
Bitmap)(e.Data.GetData(DataFormats.Bitmap))); //if ((e.KeyState & CtrlMask) != CtrlMask) //{ if (sender == pictureBox1){
pictureBox2.Image =
null;}
else{
pictureBox1.Image =
null;}
//}}
Thanks :)
EDIT: Never mind, I tryed it and it did not work...what would I do to amke it do what pressing ctrl would do without having to press ctrl
Rascal123
never mind, I found a drag and drop example...
Thanks :),
I will be having a new account today becuase I have a new e-mail, so I will be canceling this one later today, my new username should be somthing like "programmer" , just so you know I wont be a new guy.
Baok
It let me drag it everywhere but not drop it...here is all my code for this:
public partial class Form1 : Form{
const byte CtrlMask = 8; public Form1(){
InitializeComponent();
}
private void pictureBox2_DragDrop(object sender, DragEventArgs e){
// Display the image in the selected PictureBox control. PictureBox pic = ((PictureBox)(sender));pic.Image = ((
Bitmap)(e.Data.GetData(DataFormats.Bitmap))); //if ((e.KeyState & CtrlMask) != CtrlMask) //{ // if (sender == pictureBox1) // { // pictureBox2.Image = null; // } // else // { // pictureBox1.Image = null; // } //}}
private void pictureBox2_DragEnter(object sender, DragEventArgs e){
if ((e.Data.GetDataPresent(DataFormats.Bitmap))){
if ((e.KeyState & CtrlMask) == CtrlMask){
e.Effect =
DragDropEffects.Copy;}
else{
e.Effect =
DragDropEffects.Copy;}
}
else{
e.Effect =
DragDropEffects.None;}
}
private void pictureBox2_MouseDown(object sender, MouseEventArgs e){
if (e.Button == System.Windows.Forms.MouseButtons.Left){
PictureBox pic = ((PictureBox)(sender)); if (!(pic.Image == null)){
pic.DoDragDrop(pic.Image,
DragDropEffects.Copy);}
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e){
if (e.Button == System.Windows.Forms.MouseButtons.Left){
PictureBox pic = ((PictureBox)(sender)); if (!(pic.Image == null)){
pic.DoDragDrop(pic.Image,
DragDropEffects.Move | DragDropEffects.Copy);}
}
}
private void pictureBox1_DragDrop(object sender, DragEventArgs e){
PictureBox pic = ((PictureBox)(sender));pic.Image = ((
Bitmap)(e.Data.GetData(DataFormats.Bitmap))); if ((e.KeyState & CtrlMask) != CtrlMask){
if (sender == pictureBox1){
pictureBox2.Image =
null;}
else{
pictureBox1.Image =
null;}
}
}
private void pictureBox1_DragEnter(object sender, DragEventArgs e){
if ((e.Data.GetDataPresent(DataFormats.Bitmap))){
if ((e.KeyState & CtrlMask) == CtrlMask){
e.Effect =
DragDropEffects.Copy;}
else{
e.Effect =
DragDropEffects.Move;}
}
else{
e.Effect =
DragDropEffects.None;}
}
private void Form1_Load(object sender, EventArgs e){
pictureBox1.AllowDrop =
true;pictureBox2.AllowDrop =
false;}
}
}
nhaas
DragDropEffects
.Move |has to be there becuase it does everything BUT it wont drop it into the other imagebox...
Thanks :)
Salman Maredia
is there another way to do this without having it do what it is doing
Thanks :)
DavidW57
Do you want it to always copy the image sort of speaking I mean, your code as it seems will null the image in the source picture box if the ctrl key was not pressed, when the ctrl is pressed, it will leave a copy of the picture in the source. Try removing this part from your code from the pictureBox2_DragDrop handler:
if ((e.KeyState & CtrlMask) != CtrlMask){
}//Remove these lines or comment them out
Is that the effect you need
ivanatilca
Try doing this:
Replace the line:
pic.DoDragDrop(pic.Image, DragDropEffects.Move | DragDropEffects.Copy);
with
pic.DoDragDrop(pic.Image, DragDropEffects.Copy);
and if it didn't work by itself, try removing also the lines i mentioned earlier!
Hope this works!
chaza
picturebox 1 is the one that is supposed to have the images droped into...
picturebox 2 is the one that you drag the image from...
is there somthing with picturebox 1's code that needs to be changed
Thanks :)
Logan1337
Hi progames25,
Do you mean you did that an it di not drop the image at all What does your code look like now