textControl1.Load(buffer, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
我感觉这句有点问题, textControl1没有完全加载ActiveX控件就会出错。。
我的经验是:
public static class TextControlExpand
{
private static Dictionary<int, string> dic = new Dictionary<int, string>();
public static void Load(this TextControl control, string context)
{
try
{
control.Load(context, TXTextControl.StringStreamType.RichTextFormat);
}
catch (Exception)
{
dic[control.GetHashCode()] = context;
control.VisibleChanged += control_VisibleChanged;
}
}
static void control_VisibleChanged(object sender, EventArgs e)
{
TextControl ctrl = (sender as TextControl);
ctrl.VisibleChanged -= control_VisibleChanged;
ctrl.Load(dic[sender.GetHashCode()], TXTextControl.StringStreamType.RichTextFormat);
}
} |