S
Steve
Hello,
I've written a C#-based Outlook COM Add-In that uses custom images for
its buttons. The only mechanism I've found for setting a custom
button image is to paste it from the clipboard with PasteFace. Since
a common user scenario is to copy some HTML onto the clipboard, open a
new email, then paste it, I need to ensure that I save and restore the
HTML content so that the user is unaware and unaffected by the fact I
had to use the clipboard for the button images.
Below is my attempt at doing so. Unfortunately it does not work. It
works fine for saving/restoring plain text, but does not work for
HTML. Does anyone see a problem with my save/restore code or know of
how to accomplish this?
Thanks,
Steve
public void SetButtonImage(string imageFilename)
{
try
{
// save/restore data (in all of its formats) on the clipboard; this
is important so that we don't muck
// with the user's intention (for example, of pasting something into
a new email they create)
IDataObject ido = Clipboard.GetDataObject();
string[] formats = ido.GetFormats(true);
object[] savedDatam = new object[formats.Length];
int i = 0;
foreach (string format in formats)
{
//Trace.WriteLine(format);
savedDatam[i++] = ido.GetData(format);
}
string imagePathname = string.Format(@"{0}\{1}", ImagesDirPath,
imageFilename);
Clipboard.SetDataObject(Image.FromFile(imagePathname));
Trace.Assert(this.button != null);
this.button.PasteFace();
foreach (object savedData in savedDatam)
Clipboard.SetDataObject(savedData);
}
catch (Exception e)
{
Trace.WriteLine(e);
}
}
}
I've written a C#-based Outlook COM Add-In that uses custom images for
its buttons. The only mechanism I've found for setting a custom
button image is to paste it from the clipboard with PasteFace. Since
a common user scenario is to copy some HTML onto the clipboard, open a
new email, then paste it, I need to ensure that I save and restore the
HTML content so that the user is unaware and unaffected by the fact I
had to use the clipboard for the button images.
Below is my attempt at doing so. Unfortunately it does not work. It
works fine for saving/restoring plain text, but does not work for
HTML. Does anyone see a problem with my save/restore code or know of
how to accomplish this?
Thanks,
Steve
public void SetButtonImage(string imageFilename)
{
try
{
// save/restore data (in all of its formats) on the clipboard; this
is important so that we don't muck
// with the user's intention (for example, of pasting something into
a new email they create)
IDataObject ido = Clipboard.GetDataObject();
string[] formats = ido.GetFormats(true);
object[] savedDatam = new object[formats.Length];
int i = 0;
foreach (string format in formats)
{
//Trace.WriteLine(format);
savedDatam[i++] = ido.GetData(format);
}
string imagePathname = string.Format(@"{0}\{1}", ImagesDirPath,
imageFilename);
Clipboard.SetDataObject(Image.FromFile(imagePathname));
Trace.Assert(this.button != null);
this.button.PasteFace();
foreach (object savedData in savedDatam)
Clipboard.SetDataObject(savedData);
}
catch (Exception e)
{
Trace.WriteLine(e);
}
}
}