我需要在 C# 中创建不可聚焦的表单。在那个表格上会有按钮。按下该按钮后,我想将 System.Clipboard 的内容粘贴到光标所在的位置。这是我到目前为止所拥有的:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const int WS_EX_NOACTIVATE = 0x08000000;
const int WS_EX_TOPMOST = 0x00000008;
const int WS_EX_TOOLWINDOW = 0x00000080;
const int WM_MOUSEACTIVATE = 0x0021;
const int WS_EX_WINDOWEDGE = 0x00000100;
const int MA_NOACTIVATEANDEAT = 4;
const int WM_NCHITTEST = 0x0084;
//const int WM_ACTIVATEAPP = 0x001C;
const int WS_THICKFRAME = 0x00040000;
const int WS_CHILD = 0x40000000;
const int WS_BORDER = 0x00800000;
const int WS_DLGFRAME = 0x00400000;
const int WS_CAPTION = WS_BORDER | WS_DLGFRAME;
const int WS_SYSMENU = 0x00080000;
protected override bool ShowWithoutActivation { get { return true; } }
protected override CreateParams CreateParams
{
get
{
CreateParams ret = base.CreateParams;
ret.Style = WS_THICKFRAME |
WS_CHILD |
WS_CAPTION |
WS_SYSMENU;
ret.ExStyle |= WS_EX_NOACTIVATE |
WS_EX_TOOLWINDOW |
WS_EX_TOPMOST |
WS_EX_WINDOWEDGE;
ret.X = this.Location.X;
ret.Y = this.Location.Y;
return ret;
}
}
private void simpleButton1_Click(object sender, EventArgs e)
{
Clipboard.SetText("text1 text2");
SendKeys.SendWait("^v");
}
}
该表格不是我申请的主要表格。仅当焦点在我的应用程序中时,该代码才有效。如果我关注记事本或任何其他程序剪贴板内容不会粘贴到它。任何人都可以帮助解决这个问题?