I need to place RTF text in a Visio shape from a .Net application. The Visio SDK documentation says that the Shape.PasteSpecial(visPasteRichText) method on a group shape should do the trick, but I get a COM exception: "Requested operation presently disabled."
I can't find an example anywhere in this forum on anywhere else on the internet. Can anyone post an example of putting rich text in a Visio shape?
Here's my code:
using System.Windows.Forms;
using Visio = Microsoft.Office.Interop.Visio;
public void Draw()
{
// Get some rich text.
RichTextBox rtfBox = new RichTextBox();
rtfBox.Text = "This is some rich text.";
rtfBox.SelectAll();
rtfBox.SelectionColor = System.Drawing.Color.Blue;
// Copy the rich text into the clipboard.
Clipboard.SetText(rtfBox.SelectedRtf, TextDataFormat.Rtf);
// Paste the rich text into a shape.
Visio.Shape visioShape = VisioInfo.Page.DrawRectangle(2, 2, 4, 4);
visioShape.ConvertToGroup(); // This avoids "Inappropriate target object for this action" exception.
visioShape.PasteSpecial((int) (Visio.VisPasteSpecialCodes.visPasteRichText), false, false); // This line throws "Requested operation presently disabled" COM exception.
}
The exception is thrown whether or not the new shape is selected.
Thanks for any help you can give me.