DragDrop Копировать эффекты с помощью PictureBoxes? Делает ли он фактическую копию исходного файла?C#

Место общения программистов C#
Ответить
Anonymous
 DragDrop Копировать эффекты с помощью PictureBoxes? Делает ли он фактическую копию исходного файла?

Сообщение Anonymous »

Сейчас я пытаюсь создать простой эффект перетаскивания с помощью графических блоков. Он работает отлично; однако затем я пытаюсь определить файл ресурсов цели перетаскивания, чтобы узнать, нужно ли его включать или выключать.
Однако часть оператора if не работает. Я приложил все усилия, чтобы проследить интерфейс C#, чтобы увидеть, что делают их эффекты/аргументы событий DragDrop, но я не могу найти часть, где создается растровая копия. Я отладил его как можно лучше, но я в тупике. Приносим извинения за любые аномалии в коде.
Этот код компилируется и выполняется, но оператор if не срабатывает.
Я очень надеюсь, что мне не придется кодировать много случаев переключения, чтобы вывести изображение. Это было бы отстой.
В любом случае, вот соответствующие функции:
private void drag_MouseDown(object sender, MouseEventArgs e)
{
// Set parameters for the DoDragDrop method
DragDropEffects supportedEffects = DragDropEffects.Copy;
var dragPic = ((PictureBox)sender).Image;

//MessageBox.Show(((PictureBox)sender).ImageLocation); //it doesn't know its location--however, i'm using resource files so this might be why
//MessageBox.Show(dragPic.ToString()); //System.Drawing.Bitmap result
//https://stackoverflow.com/questions/160 ... to-another
//referenced this only for the image stuff; previous code didn't work during testing and I think this is why

DragDropEffects dragEffect = ((PictureBox)sender).DoDragDrop(dragPic, supportedEffects);
this.Cursor = Cursors.Default;
}

private void dropTarget_DragDrop(object sender, DragEventArgs e)
{
if (sender.GetType().ToString() == "System.Windows.Forms.PictureBox")
{
//the sender is the drop target, not the origin of the image(e. whatever)
((PictureBox)sender).Image = (Image)e.Data.GetData(DataFormats.Bitmap);
MessageBox.Show(e.Data.ToString()); //System.Windows.Forms.DataObject
//MessageBox.Show(((PictureBox)sender).ImageLocation); //this is blank, but why?? is it a copy?
((PictureBox)sender).BorderStyle = BorderStyle.None;
}

//needed to reference this for the DataFormats.Bitmap part
//https://stackoverflow.com/questions/160 ... to-another
}

private void dropTarget_DragEnter(object sender, DragEventArgs e)
{
SetDropEffect(e);
}

private void dropTarget_DragOver(object sender, DragEventArgs e)
{
SetDropEffect(e);
}

// later, this is what I'm trying to accomplish:
if (pbxStar.Image == Properties.Resources.star_off)
pbxStar.Image = Properties.Resources.star;
// the problem here is the if statement. Both the drag source and drop source
// have access to the resource files as well, so I don't really understand
// what's going on and, more importantly, how to fix it.



Подробнее здесь: https://stackoverflow.com/questions/798 ... f-the-sour
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»