2017-09-02 5 views
0

私の小さなプログラムに問題があります。ユーザードメインをクリップボードにコピーするエラー

私はそれを押したときに現在のユーザードメインをクリップボードにコピーするボタンを作成しました。

private void button2_Click(object sender, EventArgs e) 
    { 
     Clipboard.SetText(System.Net.NetworkInformation.IPGlobalProperties. 
     GetIPGlobalProperties().DomainName); 
    } 

しかし、プログラムをデバッグしてボタンを押すと、VSによって常にエラーが表示されます。

System.ArgumentNullException ist aufgetreten. 
HResult=0x80004003 
Nachricht = Der Wert darf nicht NULL sein. 
Parametername: text 
Quelle = System.Windows.Forms 
Stapelüberwachung: 
at System.Windows.Forms.Clipboard.SetText(String text, TextDataFormat 
format) 
at WindowsFormsApp1.Window.button2_Click(Object sender, EventArgs e) in 
C:\Users\user\Documents\Visual Studio 
2017\Projects\WindowsFormsApp1\WindowsFormsApp1\Form1.cs:line 120 
at System.Windows.Forms.Control.OnClick(EventArgs e) 
at System.Windows.Forms.Button.OnClick(EventArgs e) 
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, 
Int32 clicks) 
at System.Windows.Forms.Control.WndProc(Message& m) 
at System.Windows.Forms.ButtonBase.WndProc(Message& m) 
at System.Windows.Forms.Button.WndProc(Message& m) 
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 
msg, IntPtr wparam, IntPtr lparam) 
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 
at System.Windows.Forms.Application.ComponentManager.# 
System.Windows.Forms.UnsafeNat 
iveMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 
reason, Int32 pvLoopData) 
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 
reason, ApplicationContext context) 
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 
reason, ApplicationContext context) 
at WindowsFormsApp1.Program.Main() in C:\Users\user\Documents\Visual 
Studio 2017\Projects\WindowsFormsApp1\WindowsFormsApp1\Program.cs:line 18 

私はコードSystem.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName戻りnullまたはあなたのケースで空の文字列いくつかの理由で、この行と思い事前

答えて

0

でいただきありがとうございます。 MSDN Clipboard.SetTextによれば、引数がの場合、ヌルまたは空の場合が例外をスローします。

Environment.UserDomainNameを試しましたか?

+0

「Environment.UserDomainNameを試しましたか?それをありがとうございます<3 – Madison

関連する問題