Сейчас я пытаюсь создать простой эффект перетаскивания с помощью графических блоков. Он работает отлично; однако затем я пытаюсь определить файл ресурсов цели перетаскивания, чтобы узнать, нужно ли его включать или выключать.
Однако часть оператора 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
DragDrop Копировать эффекты с помощью PictureBoxes? Делает ли он фактическую копию исходного файла? ⇐ C#
Место общения программистов C#
1765388662
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/16004682/c-sharp-drag-and-drop-from-one-picture-box-into-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/16004682/c-sharp-drag-and-drop-from-one-picture-box-into-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.
Подробнее здесь: [url]https://stackoverflow.com/questions/79839308/dragdrop-copy-effects-with-pictureboxes-is-it-making-an-actual-copy-of-the-sour[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия