我在WinForms中的数字更新控件上有一个值更改事件,我在需要时更改了值。它的价值改变如下:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
if (InvokeRequired)
{
// after we've done all the processing,
this.Invoke(new MethodInvoker(delegate {
this.lblNumberOfTransactionsFetched.Text = "Fetched: " + numericUpDown1.Value + " out of " + this._sortedList.Count() + " transactions";
}));
return;
}
}
基本上我在async方法的形式上显示一个结果,该方法向PayPal发出网络请求,并且每次按下按钮时我都会尝试重置此值:
private async void materialRaisedButton3_Click(object sender, EventArgs e)
{
// Reset the numeric updown value to 0 again before it's displayed on the form again
}
我怎样才能做到这一点?
编辑:@Trey这是触发事件时我正在调用的实际代码:
private async void materialRaisedButton3_Click(object sender, EventArgs e)
{
this.materialListView1.Items.Clear();
Application.DoEvents();
_detail = new List<TransactionDetails>();
_sortedList = new List<Transactions>();
var startDate = (dateFrom.Value.Year + "-" + dateFrom.Value.Date.Month + "-" + this.dateFrom.Value.Date.Day + "T00:00:00Z");
var endDate = (dateTo.Value.Year + "-" + dateTo.Value.Date.Month + "-" + this.dateTo.Value.Date.Day + "T23:59:00Z");
if (DateTime.Parse(startDate) > DateTime.Parse(endDate))
{
MessageBox.Show("Start date cannot be higher than end date!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else if (DateTime.Parse(startDate) < DateTime.Parse(endDate))
{
lista = new List<TransactionSearchResponseType>();
transactions = new List<Transactions>();
loadingCircle1.Visible = true;
loadingCircle1.Active = true;
lblWait.Visible = true;
this.materialRaisedButton3.Enabled = false;
await DoTask(startDate, endDate);
_sortedList = transactions.DistinctBy(x => x.TransactionID).OrderByDescending(x => x.TimeStamp).ToList();
this.lblNumberOfTransactionsFetched.Visible = true;
for (int i = 0; i < _sortedList.Count(); i++)
{
await GetTransactionDetails(_sortedList[i].TransactionID, _sortedList[i].TimeZone);
}
foreach (var item in _sortedList)
{
var itemInB = _detail.Where(x => x.TransactionID == item.TransactionID).FirstOrDefault();
if (itemInB != null)
item.transactionDetails.Add(itemInB);
}
loadingCircle1.Active = false;
loadingCircle1.Visible = false;
lblWait.Visible = false;
seedListView(_sortedList);
listOfTransactionDetailsCSV = new List<TransactionDetails>();
foreach (var item in _sortedList)
{
listOfTransactionDetailsCSV.Add(item.transactionDetails[0]);
}
lblNumberOfTransactionsFetched.Visible = false;
this.materialRaisedButton3.Enabled = true;
}
}