C # WinForm copy and paste text to the clipboard

C # WinForm copy and paste text to the clipboard

//复制:

private void button1_Click(object sender, System.EventArgs e) {

  if(textBox1.SelectedText != "")

     Clipboard.SetDataObject(textBox1.SelectedText);

}

 

//粘贴:

private void button2_Click(object sender, System.EventArgs e) {

  IDataObject iData = Clipboard.GetDataObject();

  if(iData.GetDataPresent(DataFormats.Text)) {

     textBox2.Text = (String)iData.GetData(DataFormats.Text);

  }

}

  

C#WinForm中复制、粘贴文本到剪贴板

Published 17 original articles · won praise 224 · views 290 000 +

Guess you like

Origin blog.csdn.net/cxu123321/article/details/105066986