Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
if() + switch() + pictureBox [C#]

Here's the thing, I have a Windows Form with an empty pictureBox in it and some labels that get system info using wmi, the picture box is supposed to automatically get the logo of the operating system from a folder in the project called Pictures using an if statement or a switch case but I can't for the life of me come up with something that works.

The basic idea is :

if OSN contains a 7, pictureBoxOS gets the image called W7 from the pictures folder.

if OSN contains an 8, pictureBoxOS gets the image called W8 from the pictures folder so on and so forth

OSN being the OS Name

What follows is some of what's written in the SysInfo Class

public static class SysInfo
    {
        public static String GetOSName()
        {

            ManagementClass mc = new ManagementClass("Win32_OperatingSystem");
            ManagementObjectCollection moc = mc.GetInstances();
            String OSN = String.Empty;
            foreach (ManagementObject mo in moc)
            {

                OSN = mo.Properties["Caption"].Value.ToString();
                break;
            }
            return OSN;
     }

Then comes what's written in the form

public partial class FormSystemInfo : Form
    {
        public FormSystemInfo()
        {
            InitializeComponent();
            LoadTheme();
        }


        private void FormSystemInfo_Load(object sender, EventArgs e)
        {
            labelOSName.Text=SysInfo.GetOSName();
            labelOSVersion.Text=SysInfo.GetOSVersion();
            labelBrandModel.Text=SysInfo.GetBrandModel();
            labelProcessorName.Text=SysInfo.GetProcessorName();
            labelMemory.Text=SysInfo.GetPhysicalMemory();
            labelDriveID.Text=SysInfo.GetDriveID();
            labelGPUName.Text=SysInfo.GetGPUName();
            labelSerialNumber.Text = SysInfo.GetSerialNumber();

            
        }

        
    }


over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

For anyone who might stumble upon this post, I did find a way to make it work:

DirectoryInfo dir = new DirectoryInfo(Application.StartupPath);
        ManagementClass mc = new ManagementClass("Win32_OperatingSystem");
        ManagementObjectCollection moc = mc.GetInstances();
        String OSN = String.Empty;

        foreach (ManagementObject mo in moc)
        {

            OSN = mo.Properties["Caption"].Value.ToString();
            break;
        }

        if (OSN.Contains("7"))
        {
            string path = dir.Parent.Parent.Parent.FullName + @"\Pictures\W7.png";
            pictureBoxOS.Image = Image.FromFile(path);
        }
        else if (OSN.Contains("8"))
        {
            string path = dir.Parent.Parent.Parent.FullName + @"\Pictures\W8.png";
            pictureBoxOS.Image = Image.FromFile(path);
        }
        else if (OSN.Contains("10"))
        {
            string path = dir.Parent.Parent.Parent.FullName + @"\Pictures\W10.png";
            pictureBoxOS.Image = Image.FromFile(path);

        }
        else if (OSN.Contains("11"))
        {
            string path = dir.Parent.Parent.Parent.FullName + @"\Pictures\W11.png";
            pictureBoxOS.Image = Image.FromFile(path);

        }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!