2017-10-17 86 views
-2

我一直在爲這個項目工作,而messagebox沒有顯示 有人可以幫我嗎?C#MessageBox不能正常工作

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 MaterialSkin.Controls; 
using MaterialSkin.Animations; 
using MaterialSkin; 
using System.Web; 
using System.Net; 
using System.IO; 
using System.Management; 
using System.Windows; 

namespace Liquid_Reborn 
{ 
    public partial class Login : MaterialForm 
    { 
     public Login() 
     { 
      InitializeComponent(); 

      var materialSkinManager = MaterialSkinManager.Instance; 
      materialSkinManager.AddFormToManage(this); 
      materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT; 
      materialSkinManager.ColorScheme = new ColorScheme(Primary.LightBlue200, Primary.LightBlue300, Primary.LightBlue300, Accent.LightBlue200, TextShade.WHITE); 

     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      string cpuInfo = string.Empty; 
      ManagementClass mc = new ManagementClass("win32_processor"); 
      ManagementObjectCollection moc = mc.GetInstances(); 
      foreach (ManagementObject mo in moc) 
      { 
       if (cpuInfo == "") 
       { 
        //Get only the first CPU's ID 
        cpuInfo = mo.Properties["processorID"].Value.ToString(); 
        break; 
       } 
       var plainTextBytes = Encoding.UTF8.GetBytes(cpuInfo); 
       String hwid = Convert.ToBase64String(plainTextBytes); 
       WebClient client = new WebClient(); 
       Stream stream = client.OpenRead("http://techshow.us/liquid/hwid.txt/"); 
       StreamReader reader = new StreamReader(stream); 
       String content = reader.ReadToEnd(); 
       if (content.Contains(hwid)) 
       { 

       } 
       MessageBox.Show("ok"); 

      } 
     } 
    } 
} 

爲什麼不顯示消息框? 香港專業教育學院嘗試的大多數事情,沒有工作 什麼也沒有發生在用戶界面只顯示和IDK的做什麼\ 請幫助我,我需要爲我的項目

+0

集合'moc'可能是空的,這就是爲什麼循環不執行 – shahsani

+0

你是什麼意思?該代碼不在集合中 –

+0

您是否在線上放置了一個調試點來檢查它是否正在執行? – TejSoft

回答

1

if (cpuInfo == "")將永遠是正確的,因爲值沒有初始化後更改。在到達MessageBox代碼之前,循環會中斷。

刪除break;允許代碼繼續,或

使用continue;而是跳到循環中的下一個值。