[VC2005] ユーザー名を表示する方法

◆概要

この資料は、Microsoft(R) Visual C# 2005で ユーザー名を表示する方法について記述しています。

カレントユーザー名を表示するには、次のようにします。

◆フォームに準備するもの

テキストボックスtextBox1
コマンドボタンbutton1

◆Sample code


private void button1_Click(object sender, EventArgs e)
{
    DisplayUser();
}

public void DisplayUser()
{
    System.Security.Principal.WindowsIdentity currentUser
       = System.Security.Principal.WindowsIdentity.GetCurrent();
       textBox1.Text = currentUser.Name;
}
    


▼ページトップへ