在标题中的 Word 2003 自动化中使用拖放的奇怪行为

发布于 2024-08-25 18:13:51 字数 1216 浏览 6 评论 0原文

我正在为Word 2003 开发一个基于模板的插件,它允许用户将元素从列表框拖放到word 文档中。不幸的是,当我尝试在文档标题中删除元素时,我遇到了非常奇怪的行为。

  1. 打开模板并在标题中键入内容
  2. 关闭标题并在页面上插入一些内容
  3. 添加分页符。
  4. 切换到页面布局模式,并将缩放级别设置为“两页”
  5. 打开标题
  6. 缓慢地将列表项从列表框拖放到标题。
  7. 查看出现多个页面设置对话框,导致 Word 崩溃。

这是我的代码:

// in ThisDocument.cs

public MyUserControl _control;
public void Init()
{
    _control = new MyUserControl();
    ActionsPane.Controls.Add(_control);
    ActionsPane.Visible = true;
}

// in MyUserControl.cs

public void listBox1_MouseDown(object sender, MouseEventArgs e)
{
    DoDragDrop("something", DragDropEffects.Copy);
}

我在实现拖放时是否犯了一些错误?对于这种奇怪的行为有解决方法吗?

预先感谢,
Oliver Hanappi

视频

我制作了一个小视频来展示该错误。您可以从这里下载: http://rapidshare.com/files/364907873 /word-2003-bug.rar

不幸的是,我使用的工具没有注意到我更改了显示设置,所以虽然我使用了1280x768,但它记录的是1920x1200,所以对于奇怪的视频尺寸感到抱歉。如果您无法观看视频,则可能缺少编解码器。您可以在这里获取它: http://camstudio.org/

我还忘了提及该错误也发生在Word 2007。因为我本地机器上只有Word 2007,所以我用Word 2007录制视频,但与Word 2003基本相同(我发现了错误)

I am developing a template based addin for Word 2003 which allows the user to drag and drop elements from a listbox into the word document. Unfortunately I'm getting a really strange behaviour when trying to drop elements in the document's header.

  1. Open the template and type something in the header
  2. Close the header and insert some content on the page
  3. Add a page break.
  4. Switch to page layout mode where and set zoom level to "Two Pages"
  5. Open the header
  6. Slowly Drag and Drop an list item from the list box to the header.
  7. See multiple Page Setups dialogs occur which cause Word to crash.

Here is my code:

// in ThisDocument.cs

public MyUserControl _control;
public void Init()
{
    _control = new MyUserControl();
    ActionsPane.Controls.Add(_control);
    ActionsPane.Visible = true;
}

// in MyUserControl.cs

public void listBox1_MouseDown(object sender, MouseEventArgs e)
{
    DoDragDrop("something", DragDropEffects.Copy);
}

Have I done somethinkg wrong with implementing Drag and Drop? Is there a workaround for this strange behaviour?

Thanks in advance,
Oliver Hanappi

Video

I've made a little video which shows the bug. You can download it from here: http://rapidshare.com/files/364907873/word-2003-bug.rar

Unfortunately the tool I used didn't notice that I changed the display settings, so although I used 1280x768, it recorded 1920x1200, so sorry for the strange video size. If you cannot watch the video, maybe the codec is missing. You can get it here: http://camstudio.org/

I also forgot to mention that the bug also occurs in Word 2007. Because on my local machine I have only Word 2007, I recorded the video with Word 2007, but it is basically the same for Word 2003 (where I found the bug)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉溺在你眼里的海 2024-09-01 18:13:51

这在 Word 2007 中对我有用,但它似乎是一个糟糕的解决方法。尝试使用剪贴板在文档中设置关键字,然后处理 WindowSelectionChange 事件,该事件似乎在文本插入后可靠地触发,以执行您真正想要完成的操作。

public void listBox1_MouseDown(object sender, MouseEventArgs e)
{
    Clipboard.SetText("<#KEYWORD#>");
    IDataObject dObject = Clipboard.GetDataObject();

    //This is extremely buggy coming from VSTO, this is why the clipboard is used.
    DoDragDrop(dObject, DragDropEffects.All);
}

void Application_WindowSelectionChange(Microsoft.Office.Interop.Word.Selection Sel)
{
    if (Sel.Range.Text == "<#KEYWORD#>")
    {
        Sel.Range.Text = string.Empty;
        // Do some action
    }
}

This worked for me in Word 2007, but it seems like an awful work-around. Try using the clipboard to set a keyword in the document, then handle the WindowSelectionChange event that seems to fire reliably after text insertion to do what you really want to get done.

public void listBox1_MouseDown(object sender, MouseEventArgs e)
{
    Clipboard.SetText("<#KEYWORD#>");
    IDataObject dObject = Clipboard.GetDataObject();

    //This is extremely buggy coming from VSTO, this is why the clipboard is used.
    DoDragDrop(dObject, DragDropEffects.All);
}

void Application_WindowSelectionChange(Microsoft.Office.Interop.Word.Selection Sel)
{
    if (Sel.Range.Text == "<#KEYWORD#>")
    {
        Sel.Range.Text = string.Empty;
        // Do some action
    }
}
浅笑轻吟梦一曲 2024-09-01 18:13:51

在 Word 2011 for mac 中,对于 doc 和 docx 文件也会发生这种情况
还有一个问题是标题和光标的视觉重复。前两个问题是 Windows 2007 的已知问题。

Also happens in Word 2011 for mac both with doc and docx files
there is also a problem with visual duplication of headers and artifacts from cursors. The first two problems were known issues with 2007 for windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文