Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda