2012-08-14 23 views
3

有沒有一種方法可以獲取並顯示C#中應用程序設備的當前無線信號強度?我有一個應用程序檢測是否有通過計時器連接,但我需要知道當前的信號強度,然後以圖形方式顯示在狀態欄中。下面是我目前的代碼,每隔幾秒檢測一次基本連接。我可以添加什麼來顯示力量呢?謝謝。計時器代碼由S.O.給出。用戶:parapura拉庫瑪獲取並顯示窗體上的網絡信號強度

private void Form1_Load(object sender, EventArgs e) 
    {         
     //create an object to hold app settings FIRST 

     appsetting apps = new appsetting(); 
     apps.getsetting(); 
     netMessage.Clear(); 

     //creates a timer for refresh rate on connectivity check 

     var timer = new Timer(); 
     timer.Tick += new EventHandler(timer_Tick); 
     timer.Interval = 2000; //2 seconds 
     timer.Start();    
    } 


    //starts the timer 
void timer_Tick(object sender, EventArgs e) 
{ 
    //if connection is not detected 
    if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() ==f 
    false) 
    { 
     //clear the buffer 
     netMessage.Clear(); 

     //turn RED indicator on and display message 
     netConnect.BackColor = Color.Red; 
     this.netMessage.Text = ("No Connection"); 
     noConn = true;//set "No connection" to true 
     conn= false; 

    } 
    else 
     //turn GREEN indicator on and display message 
     netConnect.BackColor = Color.Lime; 
     this.netMessage.Text = ("Connected"); 
     conn = true;// set connection to "true 
     noConn = false; 

      //if box is red but connection is established, turn it back to green 


      if (noConn == true && 
      System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() == 
      true) 
      { 
       netConnect.BackColor = Color.Lime; 
       this.netMessage.Text = ("Connected"); 
       conn = true; 
       noConn = false; 
      } 

}    


    //need to display signal strength in a text box with color codes or status bar HERE     
+1

也許[這個答案](http://stackoverflow.com/a/3274126/1220971)[本問題](http://stackoverflow.com/questions/3273967/detect-wifi- C-sharp連接)可能會有所幫助。 – Bridge 2012-08-14 14:08:37

回答

0

一些研究,並參考了一些其他問題後,我能夠通過在給定的開源API來解決我的問題:managedwifi.codeplex.com

只需下載api,然後通過add-> csproj將它添加到您的項目中。

使用WlanClient類中給出的'public int RSSI'。

乾杯