0% found this document useful (0 votes)
12 views20 pages

C Shap Samples

Uploaded by

Eduh njoroge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views20 pages

C Shap Samples

Uploaded by

Eduh njoroge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Mdi parent Form

This is the project main menu.


1.Input output management
In the mdi parent form this is among the menu items and contains:
1. Files option- it implements file creation, file read and write, listing of drives and files
and viewing file information

Program Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class IO_Manager : Form

{
string Foldername = @"F:\Csharp";
string winDir = System.Environment.GetEnvironmentVariable("windir");
public IO_Manager()
{
InitializeComponent();
}
private void addListItem(string value)
{
this.listBox1.Items.Add(value);
}

private void bunifuFlatButton2_Click(object sender, EventArgs e)


{//creates files and folder on csharp
string path = textBox1.Text;
if (!File.Exists(path))
{
File.Create(@"F:\Csharp");
MessageBox.Show("file created successfully...!");
}
else
{
MessageBox.Show("file already exists");
}
}

private void bunifuFlatButton1_Click(object sender, EventArgs e)


{
string path = textBox2.Text;
if (!Directory.Exists(path))
{
Directory.CreateDirectory(@"F:\Csharp");
MessageBox.Show("SUCCESSFULLY CREATED...!");

}
else
{
MessageBox.Show("Directory already exists");
}

private void bunifuCustomTextbox1_TextChanged(object sender, EventArgs e)


{

private void bunifuCustomLabel1_Click(object sender, EventArgs e)


{

private void File_Manager_Load(object sender, EventArgs e)


{

private void bunifuFlatButton4_Click(object sender, EventArgs e)


{//displays drive and files
this.listBox1.Items.Clear();
StreamReader reader = new StreamReader(winDir + "\\system.ini");
try
{
do
{
addListItem(reader.ReadLine());
}
while (reader.Peek() != -1);
}
catch
{
addListItem("File is empty");
}
finally
{
reader.Close();
}
}

private void bunifuFlatButton5_Click(object sender, EventArgs e)


{
StreamWriter writer = new StreamWriter("E:\\directory");
writer.WriteLine("File created using StreamWriter class.");
writer.Close();
this.listBox1.Items.Clear();
addListItem("File Written to C:\\KBTest.txt");

private void bunifuFlatButton6_Click(object sender, EventArgs e)


{
this.listBox1.Items.Clear();
FileInfo FileProps = new FileInfo(winDir + "\\notepad.exe");
addListItem("File Name = " + FileProps.FullName);
addListItem("Creation Time = " + FileProps.CreationTime);
addListItem("Last Access Time = " + FileProps.LastAccessTime);
addListItem("Last Write TIme = " + FileProps.LastWriteTime);
addListItem("Size = " + FileProps.Length);
FileProps = null;

private void bunifuFlatButton7_Click(object sender, EventArgs e)


{
//Demonstrates how to obtain a list of disk drives.
this.listBox1.Items.Clear();
string[] drives = Directory.GetLogicalDrives();
foreach (string drive in drives)
{
addListItem(drive);
}

private void bunifuFlatButton8_Click(object sender, EventArgs e)


{
int count = 0;
//How to get a list of folders (example uses Windows folder).
this.listBox1.Items.Clear();
//string[] dirs = Directory.GetDirectories(winDir);
string[] dirs = Directory.GetDirectories("E:\\");
foreach (string dir in dirs)
{
count++;
addListItem(count + " " + dir);

private void bunifuFlatButton3_Click(object sender, EventArgs e)


{
//How to obtain list of files (example uses Windows folder).
this.listBox1.Items.Clear();
// string[] files = Directory.GetFiles(winDir);
string[] files = Directory.GetFiles("E:\\");
foreach (string i in files)
{
addListItem(i);
}

private void bunifuThinButton21_Click(object sender, EventArgs e)


{
this.Close();
}
}
}
2.Devices-in this we implement a program that enables opening of usb ports and disabling the
provided you are an admin of the computer.

not
Program Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Management;
using System.Security;
using System.IO.Ports;

namespace WindowsFormsApplication1
{
public partial class devices : Form
{

public devices()
{
InitializeComponent();
}
RegistryKey Regkey, RegKey2;
Int32 rValue, rsvalue, Gvalue, tvalue;
string Regpath = "System\\CurrentControlSet\\Services\\USBSTOR";
string ReadAndWriteRegPath2 = "System\\CurrentControlSet\\Control";
string ReadAndWriteRegPath = "System\\CurrentControlSet\\Control\\
StorageDevicePolicies";

private void devices_Load(object sender, EventArgs e)


{
isAdmin = IsUserAnAdmin();
if (isAdmin == false)
{
MessageBox.Show("You don't have proper privileges level to make changes,
administrators privileges are required", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
//Close();
}
else
{
Regkey = Registry.LocalMachine.OpenSubKey(Regpath, true);
Gvalue = Convert.ToInt32(Regkey.GetValue("Start"));
//check the current state of the usb/whether is enabled or disabled
if (Gvalue == 3)
{
radioButton1.Checked = true;
}
else if (Gvalue == 4)
{
radioButton2.Checked = true;
}
RegKey2 = Registry.LocalMachine.OpenSubKey(ReadAndWriteRegPath, true);
try
{
tvalue = Convert.ToInt32(RegKey2.GetValue("WriteProtect"));
if (tvalue == 1)
{
radioButton3.Checked = true;
}
else if (tvalue == 0)
{
radioButton4.Checked = true;
}
}
catch (NullReferenceException) { }
}
}

private void bunifuFlatButton1_Click(object sender, EventArgs e)


{ }

private void bunifuFlatButton2_Click(object sender, EventArgs e)


{

private void bunifuFlatButton3_Click(object sender, EventArgs e)


{ }

private void bunifuThinButton25_Click(object sender, EventArgs e)


{
this.Close();
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)


{
groupBox1.Enabled = true;
rValue = 3;
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)


{
groupBox1.Enabled = true;
rValue = 4;
}

private void radioButton3_CheckedChanged(object sender, EventArgs e)


{
rsvalue = 1;
}

private void bunifuThinButton21_Click(object sender, EventArgs e)


{
try
{
Regkey = Registry.LocalMachine.OpenSubKey(Regpath, true);
Regkey.SetValue("Start", rValue);
if (groupBox1.Enabled == true)
{
RegKey2 = Registry.LocalMachine.OpenSubKey(ReadAndWriteRegPath2, true);
RegKey2.CreateSubKey("StorageDevicePolicies");
RegKey2 = Registry.LocalMachine.OpenSubKey(ReadAndWriteRegPath, true);
RegKey2.SetValue("WriteProtect", rsvalue);
}
}
catch (Exception ex)
{ }
if ((rValue == 3) && (rsvalue == 1))
{
MessageBox.Show("USB Port were enable and Read only is enabled");
}
else if ((rValue == 3) && (rsvalue == 0))
{
MessageBox.Show("USB Port were enable and Read and write is enabled");
}
else
{
MessageBox.Show("USB Port were disable");
}

private void radioButton4_CheckedChanged(object sender, EventArgs e)


{
rsvalue = 0;
}

private void bunifuThinButton22_Click(object sender, EventArgs e)


{
Close();
}
bool isAdmin;
[DllImport("shell32")]
static extern bool IsUserAnAdmin();

}
}

3.Power options—The program restarts, shutdowns, sign user out of the computer and puts it
to sleep mode.

Program code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
public partial class power : Form
{
[DllImport("user32")]
public static extern void LockWorkStation();

public power()
{
InitializeComponent();
}
[DllImport("user32")]
public static extern bool ExitWindowsEx(GraphicsUnit uFlags, uint DwReason);

private void bunifuThinButton21_Click(object sender, EventArgs e)


{
this.Close();
}

private void bunifuThinButton22_Click(object sender, EventArgs e)


{//restarts computer
Process.Start("shutdown.exe", "-r -t 00");
}

private void bunifuThinButton24_Click(object sender, EventArgs e)

{//shurts computer
Process.Start("shutdown.exe", "-s -t 00");
}

private void bunifuThinButton25_Click(object sender, EventArgs e)


{
ExitWindowsEx(0, 0);
}

private void bunifuThinButton23_Click(object sender, EventArgs e)


{//sleep mode
LockWorkStation();
}

private void power_Load(object sender, EventArgs e)


{

}
}
}

2.Process Management
It is another mdiparent form menu item which has the processes that is it can start apps such
as word excel notepad and others. At the same time the started apps can be killed, I
implemented using the combo box whereby we select the program you want to kill.
Program code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsFormsApplication1
{
public partial class Processmgn : Form
{
public Processmgn()
{
InitializeComponent();
}

private void Processmgn_Load(object sender, EventArgs e)


{

private void bunifuThinButton21_Click(object sender, EventArgs e)


{//starts word
Process.Start("winword");
}

private void bunifuThinButton22_Click(object sender, EventArgs e)


{//starts calculator
Process.Start("calc");
}

private void bunifuThinButton23_Click(object sender, EventArgs e)


{//starts excel
Process.Start("excel");
}

private void bunifuThinButton24_Click(object sender, EventArgs e)


{//starts notepad
Process.Start("notepad");
}

private void bunifuFlatButton1_Click(object sender, EventArgs e)


{//kills the selected process
foreach (var process in Process.GetProcessesByName(comboBox1.Text))
{
process.Kill();
}
}

private void bunifuThinButton25_Click(object sender, EventArgs e)


{
this.Close();
}
}
}

Listing running processes

Program code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
using System.Diagnostics;
using System.Dynamic;

namespace WindowsFormsApplication1
{
public partial class frmprocesses : Form

public ExpandoObject GetProcessExtraInformation(int processId)


{
// Query the Win32_Process
// string query = "Select * From Win32_Process Where ProcessID = " + processId;
string query = "Select * From Win32_Process Where ProcessID = " + processId;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection processList = searcher.Get();

// Create a dynamic object to store some properties on it


dynamic response = new ExpandoObject();
response.Description = "";
response.Username = "Unknown";

foreach (ManagementObject obj in processList)


{
// Retrieve username
string[] argList = new string[] { string.Empty, string.Empty };
int returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", argList));
if (returnVal == 0)
{
// return Username
response.Username = argList[0];

// You can return the domain too like (PCDesktop-123123\Username using


instead
//response.Username = argList[1] + "\\" + argList[0];
}

// Retrieve process description if exists


if (obj["ExecutablePath"] != null)
{
try
{
FileVersionInfo info =
FileVersionInfo.GetVersionInfo(obj["ExecutablePath"].ToString());
response.Description = info.FileDescription;
}
catch { }
}
}

return response;
}
public string BytesToReadableValue(long number)
{
List<string> suffixes = new List<string> { " B", " KB", " MB", " GB", " TB", "
PB" };

for (int i = 0; i < suffixes.Count; i++)


{
long temp = number / (int)Math.Pow(1024, i + 1);

if (temp == 0)
{
return (number / (int)Math.Pow(1024, i)) + suffixes[i];
}
}

return number.ToString();
}

public frmprocesses()
{
InitializeComponent();
}

private void frmprocesses_Load(object sender, EventArgs e)


{

private void bunifuThinButton21_Click(object sender, EventArgs e)


{

// Create an array to store the processes


Process[] processList = Process.GetProcesses();

// Create an Imagelist that will store the icons of every process


ImageList Imagelist = new ImageList();
// Loop through the array of processes to show information of every process in
your console
foreach (Process process in processList)
{
// Define the status from a boolean to a simple string
string status = (process.Responding == true ? "Responding" : "Not
responding");

// Retrieve the object of extra information of the process (to retrieve


Username and Description)
dynamic extraProcessInfo = GetProcessExtraInformation(process.Id);

// Create an array of string that will store the information to display in


our
string[] row = {
// 1 Process name
process.ProcessName,
// 2 Process ID
process.Id.ToString(),
// 3 Process status
status,
// 4 Username that started the process
extraProcessInfo.Username,
// 5 Memory usage
BytesToReadableValue(process.PrivateMemorySize64),
// 6 Description of the process
extraProcessInfo.Description
};

//
// As not every process has an icon then, prevent the app from crash
try
{
Imagelist.Images.Add(
// Add an unique Key as identifier for the icon (same as the ID of
the process)
process.Id.ToString(),
// Add Icon to the List
Icon.ExtractAssociatedIcon(process.MainModule.FileName).ToBitmap()
);
}
catch { }

// Create a new Item to add into the list view that expects the row of
information as first argument
ListViewItem item = new ListViewItem(row)
{
// Set the ImageIndex of the item as the same defined in the previous
try-catch
ImageIndex = Imagelist.Images.IndexOfKey(process.Id.ToString())
};

// Add the Item


lstprocess.Items.Add(item);
}
}

private void bunifuThinButton22_Click(object sender, EventArgs e)


{
this.Close();
}

}
}

3.Memory Management
It is menu item number three in the mdi parent form. In this the program lists all the disk
partitions, the space used and space available for each partition.
Program code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
public partial class Memory : Form
{
public Memory()
{
InitializeComponent();
getdrive();

}
private void getdrive()
{

{ }

}
private void bunifuFlatButton1_Click(object sender, EventArgs e)
{
MessageBox.Show(" COMPUTER HARDWARE INFORMATION");
int NoOfDisk = 0;
foreach (DriveInfo drinfo in DriveInfo.GetDrives())
{
MessageBox.Show("DriveName" + drinfo.Name + "\n"
+ "DriveLabel :" + drinfo.VolumeLabel + "\n"
+ "Total Space:" + drinfo.TotalSize / 1073741824 + " GB\n"
+ "Total Free Space:" + drinfo.TotalFreeSpace / 1073741824 + " GB\n"
+ "DriveType :" + drinfo.DriveType
);
}
MessageBox.Show("Total Disk:" + (NoOfDisk - 1).ToString());
}

private void bunifuThinButton25_Click(object sender, EventArgs e)


{
this.Close();
}

private void Memory_Load(object sender, EventArgs e)


{

}
}
}

4.Communication Management
In communication management I implemented sockets, signals, Rpc and Serial
communication. Serial communication enables communication between ports (COM3,
COM4, COM5). Rpc implements remote communication where commands are typed in the
command prompt. Signals implement the use of timers for an event to occur.

 Serial Communication

Program Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;

namespace WindowsFormsApplication1
{
public partial class communication : Form
{
public communication()
{
InitializeComponent();
}

private void communication_Load(object sender, EventArgs e)


{
string[] ports = SerialPort.GetPortNames();
comboBox1.Items.AddRange(ports);
comboBox1.SelectedIndex = 0;
bunifuThinButton22.Enabled = false;
}

private void bunifuThinButton21_Click(object sender, EventArgs e)


{
bunifuThinButton22.Enabled = true;
bunifuThinButton21.Enabled = false;
try
{
serialPort1.PortName = comboBox1.Text;
serialPort1.Open();
}
catch (Exception ex) {

MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK,


MessageBoxIcon.Error);
}

private void bunifuThinButton23_Click(object sender, EventArgs e)


{

try
{
if (serialPort1.IsOpen)
{
serialPort1.WriteLine(textBox1.Text+Environment.NewLine);
textBox1.Clear();
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK,


MessageBoxIcon.Error);
}
}

private void bunifuThinButton22_Click(object sender, EventArgs e)


{
bunifuThinButton22.Enabled = false;
bunifuThinButton21.Enabled = true;
try
{

serialPort1.Open();
}
catch (Exception ex)
{

MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK,


MessageBoxIcon.Error);
}
}

private void bunifuThinButton24_Click(object sender, EventArgs e)


{
try
{
if (serialPort1.IsOpen)
{
textBox2.Text = serialPort1.ReadExisting();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}

private void communication_FormClosing(object sender, FormClosingEventArgs e)


{
if (serialPort1.IsOpen)
serialPort1.Close();
}

private void bunifuThinButton25_Click(object sender, EventArgs e)


{
this.Close();
}
}
}

 RPC

Program code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Rpc : Form
{
public Rpc()
{
InitializeComponent();
}

private void Rpc_Load(object sender, EventArgs e)


{
string[] passedInAgs = Environment.GetCommandLineArgs();
if ((passedInAgs.Contains("/h") || passedInAgs.Contains("/H")))
{
MessageBox.Show("You called Help, you got helP!");
}
else
{
foreach (string s in passedInAgs)
{
listBox1.Items.Add(s);
}

}
}
}
}

 Signal

Program Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
pictureBox1.Visible = true;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
}

private void pictureBox1_Click(object sender, EventArgs e)


{

private void timer1_Tick(object sender, EventArgs e)


{
if (pictureBox1.Visible == true)
{
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = true;
}
else if(pictureBox3.Visible == true)
{
pictureBox1.Visible = false;
pictureBox2.Visible = true;
pictureBox3.Visible = false;
}
else if (pictureBox2.Visible == true)
{
pictureBox1.Visible = true;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
}

private void bunifuThinButton21_Click(object sender, EventArgs e)


{
timer1.Enabled = true;
}

private void bunifuThinButton22_Click(object sender, EventArgs e)


{
timer1.Enabled = false;
}

private void Form1_Load(object sender, EventArgs e)


{

}
}
}

 Socket

Program Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;

namespace monday
{
public partial class socket : Form
{
Socket sck;
EndPoint epLocal, epRemote;
byte[] buffer;
public socket()
{
InitializeComponent();
}

private void button3_Click(object sender, EventArgs e)


{
this.Hide();
}

private void socket_Load(object sender, EventArgs e)


{
sck = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);
sck.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReuseAddress,true);
textLocalIP.Text = GetLocalIP();
textRemoteIp.Text = GetLocalIP();

}
private string GetLocalIP()
{
IPHostEntry host;
host= Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList) {
if (ip.AddressFamily == AddressFamily.InterNetwork)
return ip.ToString();
}
return "10.10.152.212";
}

private void buttonconect_Click(object sender, EventArgs e)


{

epLocal = new IPEndPoint(IPAddress.Parse(textLocalIP.Text),


Convert.ToInt32(textLocalPort.Text));
sck.Bind(epLocal);
//epremote = new
IPEndPoint(IPAddress.Parse(textremoteip.Text ),Convert.ToInt32(textremoteport));
epRemote = new IPEndPoint(IPAddress.Parse(textRemoteIp.Text),
Convert.ToInt32(textRemotePort.Text));
sck.Connect(epRemote);
buffer= new byte[1500];
sck.BeginReceiveFrom(buffer,0,buffer.Length,SocketFlags.None,ref epRemote,new
AsyncCallback(MessageCallBack),buffer);
if (textRemotePort == textLocalPort)
{
MessageBox.Show(" connection failure");
}
else { MessageBox.Show("Connection established"); }
}
private void MessageCallBack(IAsyncResult aResult)
{
try
{
byte[] ReceavedData = new byte[1500];
ReceavedData = (byte[])aResult.AsyncState;
ASCIIEncoding aEncoding = new ASCIIEncoding();
string ReceavedMessage = aEncoding.GetString(ReceavedData);

listmesage.Items.Add("receaver:" + ReceavedMessage);
buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref
epRemote, new AsyncCallback(MessageCallBack), buffer);
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
}

private void buttonsend_Click(object sender, EventArgs e)


{
ASCIIEncoding aEncoding = new ASCIIEncoding();
byte[] sendingMessage = new byte[1500];
sendingMessage = aEncoding.GetBytes(textmesage.Text);
sck.Send(sendingMessage);
listmesage.Items.Add("sender: " +textmesage.Text);
listBoxfr.Items.Add("sender: " + textmesage.Text);
textmesage.Text = " ";

private void button1_Click(object sender, EventArgs e)


{
ASCIIEncoding aEncoding = new ASCIIEncoding();
byte[] sendingMessage = new byte[1500];
sendingMessage = aEncoding.GetBytes(textBox.Text);
sck.Send(sendingMessage);
listBoxfr.Items.Add("receaver: " + textBox.Text);
listmesage.Items.Add("receaver: " + textBox.Text);
textBox.Text = " ";
}

private void listmesage_SelectedIndexChanged(object sender, EventArgs e)


{

}
}

5.Information Management
This gives the device name and the user logged in. It Displays the Pc Ip address.

Program Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;

namespace WindowsFormsApplication1
{
public partial class frminformation : Form
{
public frminformation()
{
InitializeComponent();
}

private void frminformation_Load(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
string comname = System.Windows.Forms.SystemInformation.ComputerName;
string username = System.Windows.Forms.SystemInformation.UserName;
textBox1.Text = comname;
textBox2.Text = username;
}

private void button3_Click(object sender, EventArgs e)


{
IPAddress[] localIP = Dns.GetHostAddresses(Dns.GetHostName());
foreach (IPAddress address in localIP)
{ textBox3.Text = address.ToString(); }
}
}
}

You might also like