各位大佬,请问C#如何将一个现有软件的进度条映射到winform中progresbar控件作为进度值?
详细需求是将另一个应用软件(ABC)中的进度条同步映射到winform中的进度条上并在软件ABC,目前我通过while循环获得了软件ABC中进度条的百分比数字result,但result暂时只是循环的内部变量,不知道如何将result实时传递给winform的进度条控件实时显示。求各位大佬不吝赐教,指导一下小白。由于是还在入门的小白,最好是有代码可以参考,不然只有思路的话可能听不太懂,谢谢!
问题分解一下如下:
1)如何将result传递到外部函数并实现同步打印出来;
2)如何将result传递给progressbar控件作为进度值显示;
获取result的代码如下。
AutomationElement formABC = null;
AutomationElement root = AutomationElement.RootElement;
int numWait = 0;
do
{
formABC = root.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "ABC));
Thread.Sleep(50);
numWait++;
} while (numWait < 500 && null == formABC);
if (null == formABC)
{
throw new NullReferenceException("Could not find ABC");
}
else
{
AutomationElement formProgramming = formDPS.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Programming1"));
AutomationElement textPercent = formProgramming.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "1031"));
AutomationElement textElapsedTime = formProgramming.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "1032"));
while (!errorFlag && !successFlag)
{
string percent = UIA.TextGet(textPercent);
string time = UIA.TextGet(textElapsedTime);
Console.WriteLine("{0},{1}", percent, time);
int result = Convert.ToInt32(Regex.Replace(percent, @"[^0-9]+", ""));
//Console.WriteLine(result);
Thread.Sleep(1000);