2017-09-02 101 views
-1

我有一個小問題,我的計劃......從ComboBox將選定文本複製到剪貼板

我有4個變量和一個按鈕的組合框的文本在ComboBox複製。

如果我選擇在組合框中 的第一個,按複印鍵測試結束和VS說:

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 
+0

請提供您的'WindowsFormsApp1.Form1.button2_Click'方法的代碼。 –

+0

我可憐的德語足以解決問題。你讀過例外嗎? 'Nachricht = Der Wert darf nicht NULL sein.' –

+0

private void button2_Click(object sender,EventArgs e) { Clipboard.SetText(comboBox1.SelectedText); } –

回答

0

只用異常文本這是一個有點難以啓齒,但它聽起來像您可能試圖將空或空字符串複製到剪貼板。 C#不允許您將空字符串複製到剪貼板,並會拋出此錯誤。