C
ChrisW123
Hi Everyone,
I'm hoping someone here can help me. Using C#, I am dragging/dropping a
..png image into a Word document using the code below. This works fine,
creating an InlineImage in my document which contains the image.
My problems are:
1) After completing the drop, I need to be able to access the InlineShape
that was created, in order to set the .AlternateText property. How do I
reference the newly created InlineShape?
2) After completing the drop, the Font of the text near the image changes to
Times Roman for some reason. How do I prevent this from happening and
preserve the original font?
Any help is greatly appreciated, thanks in advance.
private void borSignaturePic_MouseMove(object sender, MouseEventArgs
e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
// If the mouse moves outside the rectangle, start the drag.
if (dragBoxFromMouseDown != Rectangle.Empty &&
!dragBoxFromMouseDown.Contains(e.X, e.Y))
{
// Add our .png image to the Clipboard
Clipboard.SetImage(Bitmap.FromFile(@"C:\MyImage.png"));
// Copy the image data to a Rich Text object
RichTextBox rtb = new RichTextBox();
rtb.Paste();
// Build the drag/drop Item
object item = new DataObject("Rich Text Format",
rtb.Rtf);
// Drag item to Word, creating an InlineShape with the
image in Word at the
// point of the cursor.
DragDropEffects dropEffect =
borSignaturePic.DoDragDrop(item, DragDropEffects.Copy);
// Release our Rich Text object
rtb.Dispose();
}
}
Any help at all is appreciated.
Thanks, -Chris W.
I'm hoping someone here can help me. Using C#, I am dragging/dropping a
..png image into a Word document using the code below. This works fine,
creating an InlineImage in my document which contains the image.
My problems are:
1) After completing the drop, I need to be able to access the InlineShape
that was created, in order to set the .AlternateText property. How do I
reference the newly created InlineShape?
2) After completing the drop, the Font of the text near the image changes to
Times Roman for some reason. How do I prevent this from happening and
preserve the original font?
Any help is greatly appreciated, thanks in advance.
private void borSignaturePic_MouseMove(object sender, MouseEventArgs
e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
// If the mouse moves outside the rectangle, start the drag.
if (dragBoxFromMouseDown != Rectangle.Empty &&
!dragBoxFromMouseDown.Contains(e.X, e.Y))
{
// Add our .png image to the Clipboard
Clipboard.SetImage(Bitmap.FromFile(@"C:\MyImage.png"));
// Copy the image data to a Rich Text object
RichTextBox rtb = new RichTextBox();
rtb.Paste();
// Build the drag/drop Item
object item = new DataObject("Rich Text Format",
rtb.Rtf);
// Drag item to Word, creating an InlineShape with the
image in Word at the
// point of the cursor.
DragDropEffects dropEffect =
borSignaturePic.DoDragDrop(item, DragDropEffects.Copy);
// Release our Rich Text object
rtb.Dispose();
}
}
Any help at all is appreciated.
Thanks, -Chris W.