反转进度条值 [英] Reverse progress bar values

查看:89
本文介绍了反转进度条值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究RFID项目。我在VB.Net中使用Visual Studio 2008开发了一个简单的基于桌面的GUI。我必须使用VS2008,因为我正在使用Windows PDA设备,以便我可以在Windows PDA上部署我的应用程序。 (手持式读卡器AB700)



所以我正在使用PDA扫描RFID标签。 RFID标签的范围从39到85不等。如果RFID范围值小于39或大于85,那么RFID标签将被视为超出范围。如果RFID标签靠近PDA,则值为39或40.如果RFID标签远离PDA,那么该值将为80到85.因此,当我们将RFID标签靠近或更远时,值会根据距离而变化。



我想在进度条中反映这个范围。因此,如果RFID标签靠近PDA,那么我想显示进度条已满,当它消失时,我想降低进度条的值。



< b>我尝试过:



 public void checkRFIDRange()
{
try
{
string Msg = string.Empty;
string temp = new string();
rfid.getResult(temp)//从RFID PDA获取数据并将其存储到临时变量中的函数
Msg = temp.Substring(0,temp.IndexOf(char.MinValue)); //从temp

string epc =中提取RFID标签值; // RFID标签的价值
string rssi =// RFID范围的价值

progressBar1.value = rssi;
}

catch()
{
// catch block
}
}





我将进度条的最小值设置为39,将最大值设置为85.(这没有任何巨大的差异)。我在循环中运行此代码。这样我就可以不断获得RFID范围值。



请给我任何建议

解决方案

这个简单的数学公式是

 pbValue =(85  -  value)+ 39 = 124  -  value 



39,这将返回85;为40,84;依此类推,直到85,它将返回39。


循环在.NET应用程序中是一个坏主意:除非它们与原始UI线程位于不同的线程上 - 并且你的不是t - 在循环结束并且代码返回正常处理并且可以响应Paint事件之前,UI本身不会更新。所以当你循环运行时,你不会看到任何变化!



对于这种事情,有两种方法可以做到:

1)最简单的方法是不使用循环,但使用定时读取级别的Timer - 1/10秒可能就足够了 - 并更新进度条。

2)更复杂的方法是启动一个新线程来监控级别,然后通过更新重新发布回主线程,以便更新进度条 - 它必须是这样的,因为您无法从创建它们的线程外部访问UI元素:UI线程。一种方法是使用 BackgroundWorker Class(System .ComponentModel) [ ^ ]实例 - 它具有内置于类中的进度更新,因此它比使用调用控件将代码移回UI线程以进行更新更加简单。 / BLOCKQUOTE>

I am working on RFID project. I developed an simple desktop based GUI using Visual Studio 2008 in VB.Net. I have to use VS2008 because I am working on windows PDA device so that I can deploy my app on windows PDA. (Handheld Reader AB700)

So I am scanning for RFID tag using PDA. Range of RFID tag is varies from 39 to 85. Means if RFID range value is less than 39 or is greater than 85 then that RFID tag will be considered as out of range. If the RFID tag is close to PDA then the value will be 39 or 40. If RFID tag is far from PDA then the value will be 80 to 85. So as we bring RFID tag closer or farther, the values get change according to distance.

I want to reflect this range in progress bar. So if RFID tag is close to PDA then I want to show progress bar as full and as it goes away, I want to decrease the value of progress bar.

What I have tried:

public void checkRFIDRange()
{
	try
	{
		string Msg=string.Empty;
		string temp=new string();
		rfid.getResult(temp) //Function to get data from RFID PDA and store it into temp variable
		Msg=temp.Substring(0,temp.IndexOf(char.MinValue)); //extract RFID tag value from temp
		
		string epc=""; //value of RFID tag
		string rssi="" //value of RFID range
		
		progressBar1.value=rssi;
	}
	
	catch()
	{
		//catch block
	}
}



I set the min value of progress bar as 39 and max value as 85. (Which does't made any huge difference). I am running this code in a loop. So that I will get the value of RFID range value continuously.

Please provide me any suggestions

解决方案

Well the simple mathematical formula for this is

pbValue = (85 - value) + 39 = 124 - value


For 39, this will return 85; for 40, 84; and so on until 85, where it will return 39.


Loops are a bad idea in .NET applications: unless they are on a different thread than the original UI thread - and yours isn't - the UI itself doesn't get updated until the loop ends and code returns to "normal processing" and can respond to Paint events. So while you loop runs, you don't get to see any changes!

For this kind of thing, there are two ways to do it:
1) The easiest way is to not use a loop, but use a Timer which reads the level periodically - 1/10 second would probably be enough - and updates the progress bar.
2) The more complex way is to start a new thread to monitor the levels, and repost back to the main thread with updates so it can update the Progress bar - it has to be like that, because you can't access UI elements from outside the thread they were created on: the UI thread. One way to do that is to use a BackgroundWorker Class (System.ComponentModel)[^] instance - it has progress updating built in to the class, so it makes life a lot simpler than teh alternative of Invoking controls to move code back to the UI thread for the update.


这篇关于反转进度条值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆