How to handle a blocked clipboard and other oddities

前端 未结 8 2026
闹比i
闹比i 2020-12-02 10:03

Over the course of the last couple of hours I have been tracking down a fairly specific bug with that occurs because another application has the clipboard open. Essentially

8条回答
  •  盖世英雄少女心
    2020-12-02 10:39

    Just call this first:

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    static extern IntPtr CloseClipboard();
    

    I noticed that if you're in the middle of a paste operation (WM_PASTE message), including during the TextChanged event, the clipboard remains locked by the window (the TextBox) receiving the event. So if you just call that "CloseClipboard" method inside the event handler, then you can call the managed Clipboard.Clear and Clipboard.SetText methods without any issues or delays.

提交回复
热议问题