我想在C#代码中显示确认框.我已经看到了上面的解决方案,但它在'Yes'显示异常,因为'System.Nullable'不包含'Yes'的定义.我该如何删除此错误?
private void listBox1_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
if (sender is ListBoxItem)
{
ListBoxItem item = (ListBoxItem)sender;
Harvest_TimeSheetEntry entryToDelete = (Harvest_TimeSheetEntry)item.DataContext;
DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("Are you sure?", "Delete Confirmation", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes) // error is here
{
Globals._globalController.harvestManager.deleteHarvestEntry(entryToDelete);
}
else
{
System.Windows.MessageBox.Show("Delete operation Terminated");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我想以编程方式将上下文菜单添加到我的托盘图标,这样当我右键单击托盘图标时,它应该显示菜单.如何为托盘图标编写右键单击事件处理程序?
我试过以下:
private void Icon_MouseRightClick(object sender, MouseButtonEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left) // shows error ate button
{
return;
}
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
// code for adding context menu
}
}
Run Code Online (Sandbox Code Playgroud)
声明Eventhandler为,
NotifyIcon.MouseRightClick += new MouseButtonEventHandler(NotifyIcon_MouseRightClick);
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我不明白如何处理system.format异常.见下面的代码
public Harvest_Project(XmlNode node)
{
this._node = node;
this._name = node.SelectSingleNode("name").InnerText;
this._created_at = storeTime(node.SelectSingleNode("created-at").InnerText);
this._updated_at = storeTime(node.SelectSingleNode("updated-at").InnerText);
this._over_budget_notified_at = storeTime(node.SelectSingleNode("over-budget-notified-at").InnerText);
this._latest_record_at = storeTime(node.SelectSingleNode("hint-latest-record-at").InnerText);
this._earliest_record_at = storeTime(node.SelectSingleNode("hint-earliest-record-at").InnerText);
this._billable = bool.Parse(node.SelectSingleNode("billable").InnerText);
try
{
this._id = Convert.ToInt32(node.SelectSingleNode("id").InnerText);
this._client_id = Convert.ToInt32(node.SelectSingleNode("client-id").InnerText);
this._budget = float.Parse(node.SelectSingleNode("budget").InnerText);
this._fees = Convert.ToInt32(getXmlNode("fees", node));
}
catch (FormatException e)
{
Console.WriteLine();
}
catch (OverflowException e)
{
Console.WriteLine("The number cannot fit in an Int32.");
}
this._code = node.SelectSingleNode("code").InnerText;
this._notes = node.SelectSingleNode("notes").InnerText;
}
Run Code Online (Sandbox Code Playgroud)
在这里,尝试并捕获块,所有节点都采用int值,但是,因为_fees取"0"值.它显示了格式异常.我只是希望我的节点不显示空字符串.我想处理这个异常.这意味着,它不应该在"this._fees = Convert.ToInt32(getXmlNode("fees",node))"行中抛出异常;" 因为它返回了我想要的int值.
我怎么能实现这一目标?