Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to convert code to winform?
    text
    copied!<p>Writing my first C# application...never touched the language before and not much of a programmer! I have been googling around and got a few books but thought the best way to learn is to actually try some coding!</p> <p>Anyway, been asked to write a little inventory system for all our 15000 servers and I can do this in powershell fine but wanted a challenge and try my hand at C#.</p> <p>I have the below code and this works fine in a command propmpt window but how to I put this into a winform app? I assume I need to change the "Console.WriteLine" to something else...just I do not know what the something else is! I will probably add in a listbox to show the details in there rather than executing a command prompt..</p> <p>I will be ading in loads of stuff - like memory info and disk sizes etc so getting this right would help me...plus, no doubt I will ask loads of questions!</p> <p>Code that works:</p> <pre><code>using System; namespace OsVersionSample { class Program { static void Main(string[] args) { Console.WriteLine("Operating System Detaiils"); OperatingSystem os = Environment.OSVersion; Console.WriteLine("OS Version: " + os.Version.ToString()); Console.WriteLine("OS Platoform: " + os.Platform.ToString()); Console.WriteLine("OS SP: " + os.ServicePack.ToString()); Console.WriteLine("OS Version String: " + os.VersionString.ToString()); Console.WriteLine(); // Get Version details Version ver = os.Version; Console.WriteLine("Major version: " + ver.Major); Console.WriteLine("Major Revision: " + ver.MajorRevision); Console.WriteLine("Minor version: " + ver.Minor); Console.WriteLine("Minor Revision: " + ver.MinorRevision); Console.WriteLine("Build: " + ver.Build); Console.ReadLine(); } } } </code></pre> <p>Code I want to put into a winform:</p> <pre><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; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Console.WriteLine("Operating System Detaiils"); OperatingSystem os = Environment.OSVersion; Console.WriteLine("OS Version: " + os.Version.ToString()); Console.WriteLine("OS Platoform: " + os.Platform.ToString()); Console.WriteLine("OS SP: " + os.ServicePack.ToString()); Console.WriteLine("OS Version String: " + os.VersionString.ToString()); Console.WriteLine(); // Get Version details Version ver = os.Version; Console.WriteLine("Major version: " + ver.Major); Console.WriteLine("Major Revision: " + ver.MajorRevision); Console.WriteLine("Minor version: " + ver.Minor); Console.WriteLine("Minor Revision: " + ver.MinorRevision); Console.WriteLine("Build: " + ver.Build); Console.ReadLine(); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload