C# 将所选文本从组合框复制到剪贴板

C# 将所选文本从组合框复制到剪贴板,c#,C#,我的程序有点问题 我有一个带有4个变量的组合框和一个复制组合框中文本的按钮 如果我在组合框中选择第一个 然后按下复制按钮,测试结束,vs saýs: System.ArgumentNullException ist aufgetreten. HResult=0x80004003 Nachricht = Der Wert darf nicht NULL sein. Parametername: text Quelle = System.Windows.Forms Stapelüberwachung

我的程序有点问题

我有一个带有4个变量的组合框和一个复制组合框中文本的按钮

如果我在组合框中选择第一个 然后按下复制按钮,测试结束,vs saýs:

System.ArgumentNullException ist aufgetreten.
HResult=0x80004003
Nachricht = Der Wert darf nicht NULL sein.
Parametername: text
Quelle = System.Windows.Forms
Stapelüberwachung:
bei System.Windows.Forms.Clipboard.SetText(String text, TextDataFormat format)
bei System.Windows.Forms.Clipboard.SetText(String text)
bei WindowsFormsApp1.Form1.button2_Click(Object sender, EventArgs e) in 
C:\Users\user\source\repos\WindowsFormsApp1\WindowsFormsApp1\Form1.cs: Zeile34
bei System.Windows.Forms.Control.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
bei System.Windows.Forms.Button.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager. 
System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.
FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 
reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 
reason, ApplicationContext context)
bei System.Windows.Forms.Application.Run(Form mainForm)
bei WindowsFormsApp1.Program.Main() in C:\Users\user\source\repos\WindowsFormsApp1\WindowsFormsApp1\Program.cs: Zeile19

仅使用异常文本有点难分辨,但听起来您可能试图将空字符串或空字符串复制到剪贴板。C#不允许您将空字符串复制到剪贴板,并将抛出此错误。

请提供您的
windowsformsap1.Form1.button2_单击
方法的代码。我糟糕的德语足以解决此问题。你读过例外吗
Nachricht=Der Wert darf nicht NULL sein.
private void button2\u单击(对象发送者,事件参数){Clipboard.SetText(comboBox1.SelectedText);}