how to make an image draggable?

  • Thread starter Thread starter Lloyd Dupont
  • Start date Start date
L

Lloyd Dupont

I try to implement Drag & Drop in my application.
It works rather well except I'm not able to drag in other application like,
say, word.

I tryed to look at what IE does and when I drag animage from IE it has the
follwoing formats:
[0]: "UntrustedDragDrop"
[1]: "FileDrop"
[2]: "FileNameW"
[3]: "FileName"
[4]: "DeviceIndependentBitmap"
[5]: "HTML Format"

In my code I created my 'drag value' as follow:

byte[] imageData = ....;
Bitmap bmp = new Bimtap(new MemoryStream(imageData));


DataObject dao = new DataObject();
dao.SetData(DataFormats.Bitmap, bmp);
dao.SetData("DeviceIndependentBitmap", imageData);

But that doesn't work....
Beside when I drag from IE the form DeviceIndependantBitmap is a stream,
whereas with my code I generetae either a byte[] or a proxy

what could I do?
I would like to drag image from my application without having to save them
to a file....
 
The .Net clipboard format "DeviceIndependentBitmap" expects a stream
consisting of a packed DIB.

The packed DIB's layout is as follows:
BITMAPINFOHEADER
ColorTable or Bitfields, if necessary
Bitmap's bits

When you open a bitmap as a stream, the stream consists of
a BITMAPFILEHEADER plus the packed DIB structure
outlined above.

All you need to do is create a MemoryStream representing the packed DIB
and read the bytes after the BITMAPFILEHEADER into your new stream.
 
Thanks Michael..

Michael Phillips said:
The .Net clipboard format "DeviceIndependentBitmap" expects a stream
consisting of a packed DIB.

The packed DIB's layout is as follows:
BITMAPINFOHEADER
ColorTable or Bitfields, if necessary
Bitmap's bits

When you open a bitmap as a stream, the stream consists of
a BITMAPFILEHEADER plus the packed DIB structure
outlined above.

All you need to do is create a MemoryStream representing the packed DIB
and read the bytes after the BITMAPFILEHEADER into your new stream.


Lloyd Dupont said:
I try to implement Drag & Drop in my application.
It works rather well except I'm not able to drag in other application
like, say, word.

I tryed to look at what IE does and when I drag animage from IE it has
the follwoing formats:
[0]: "UntrustedDragDrop"
[1]: "FileDrop"
[2]: "FileNameW"
[3]: "FileName"
[4]: "DeviceIndependentBitmap"
[5]: "HTML Format"

In my code I created my 'drag value' as follow:

byte[] imageData = ....;
Bitmap bmp = new Bimtap(new MemoryStream(imageData));


DataObject dao = new DataObject();
dao.SetData(DataFormats.Bitmap, bmp);
dao.SetData("DeviceIndependentBitmap", imageData);

But that doesn't work....
Beside when I drag from IE the form DeviceIndependantBitmap is a stream,
whereas with my code I generetae either a byte[] or a proxy

what could I do?
I would like to drag image from my application without having to save
them to a file....
 
Another way is to use the rtf data of the image and drag that.

Here's what to do...Open Word Pad. Drag and Drop your image into Word Pad
(and nothing but the image). Save the document as rtf. Close it and open
the document in Notepad. Notepad will display all the rtf data. Copy all the
rtf data and then, for your drag drop, do:

string rtfcode = @"rtfcode goes here";
object rtfDropData = new DataObject(DataFormats.Rtf, rtfcode);
YourControl.DoDragDrop(rtfDropData, DragDropEffects.Copy);

Now when you drag and drop the rtf data into word, your image will appear



Lloyd Dupont said:
Thanks Michael..

Michael Phillips said:
The .Net clipboard format "DeviceIndependentBitmap" expects a stream
consisting of a packed DIB.

The packed DIB's layout is as follows:
BITMAPINFOHEADER
ColorTable or Bitfields, if necessary
Bitmap's bits

When you open a bitmap as a stream, the stream consists of
a BITMAPFILEHEADER plus the packed DIB structure
outlined above.

All you need to do is create a MemoryStream representing the packed DIB
and read the bytes after the BITMAPFILEHEADER into your new stream.


Lloyd Dupont said:
I try to implement Drag & Drop in my application.
It works rather well except I'm not able to drag in other application
like, say, word.

I tryed to look at what IE does and when I drag animage from IE it has
the follwoing formats:
[0]: "UntrustedDragDrop"
[1]: "FileDrop"
[2]: "FileNameW"
[3]: "FileName"
[4]: "DeviceIndependentBitmap"
[5]: "HTML Format"

In my code I created my 'drag value' as follow:

byte[] imageData = ....;
Bitmap bmp = new Bimtap(new MemoryStream(imageData));


DataObject dao = new DataObject();
dao.SetData(DataFormats.Bitmap, bmp);
dao.SetData("DeviceIndependentBitmap", imageData);

But that doesn't work....
Beside when I drag from IE the form DeviceIndependantBitmap is a stream,
whereas with my code I generetae either a byte[] or a proxy

what could I do?
I would like to drag image from my application without having to save
them to a file....
 
Back
Top