这是设置动态Edit→的正确代码Copy mnuStripItem
吗?
此代码用于复制用户突出显示的任何内容,并且可以正确输出。
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
Form f = Form.ActiveForm;
// Find the control that has focus
Control focusedControl = f.ActiveControl;
// See if focusedControl is of a type that can select text/data
if (focusedControl is TextBox)
{
TextBox tb = focusedControl as TextBox;
Clipboard.SetDataObject(tb.SelectedText);
}
else if (focusedControl is DataGridView)
{
DataGridView dgv = focusedControl as DataGridView;
Clipboard.SetDataObject(dgv.GetClipboardContent());
}
//else if (...more?...)
//{
//}
}