2012-08-14 73 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'。

干杯