【问题标题】:Prompt dialog in C# WinFormsC# WinForms 中的提示对话框
【发布时间】:2013-08-20 08:00:05
【问题描述】:

我正在用 c++ 编写一个小项目并将其打包到 GUI 中。参考源代码为enter link description here(下载源代码 - 61.1 Kb)

我想在选择“菜单”-“编辑”-“参数设置”时提示一个对话窗口。我已经画了一个这样的对话框

点击“参数设置”时

private void menuItem7_Click(object sender, EventArgs e)
{
   if (drawArea.GraphicsList.ShowFormParameter(this))
   {
      drawArea.SetDirty();
      drawArea.Refresh();
   }
}


public bool ShowFormParameter(IWin32Window parent)
{
   return true;
}

但它不起作用,单击时对话框不显示。我怎么能意识到这一点?

【问题讨论】:

  • 这里出了点大问题...您正在谈论创建 MFC 应用程序,并且您已标记问题 c++mfc,但您显示的代码显然是C# 并使用 WinForms 框架。更糟糕的是,问题上有一个c# 标签。所以我不知道你实际上想做什么。 MFC 不适用于 C#。 MFC部分只是一个红鲱鱼吗?您实际上只是在创建一个 C# WinForms 应用程序吗?

标签: c# winforms


【解决方案1】:

您发布的所有代码实际上都没有显示对话框。您使用 ShowDialog 成员函数来执行此操作,但您没有调用该函数。

断章取意,我真的不知道ShowFormParameter 函数的用途是什么。我想这是通过将代码以在单个函数中显示参数对话框来模块化代码的尝试。

无论如何,您需要在此函数中编写代码才能真正显示您创建的对话框:

public bool ShowFormParameter(IWin32Window parent)
{
   // This creates (and automatically disposes of) a new instance of your dialog.
   // NOTE: ParameterDialog should be the name of your form class.
   using (ParameterDialog dlg = new ParameterDialog())
   {
       // Call the ShowDialog member function to display the dialog.
       if (dlg.ShowDialog(parent) == DialogResult.OK)
       {
           // If the user clicked OK when closing the dialog, we want to
           // save its settings and update the display.
           //
           // You need to write code here to save the settings.
           // It appears the caller (menuItem7_Click) is updating the display.
           ... 

           return true;               
       }
   }
   return false;  // the user canceled the dialog, so don't save anything
}

【讨论】:

  • 想再提一个奇迹,虽然和主题关系不大。参考源代码演示了一个绘图工具。那么如果我在绘图区域绘制一个矩形,是否可以从代码中提取形状参数(例如DrawRectangle.cs中的x,y,width,height)然后显示在新的对话框中?
  • @qingyao 使用“”按钮提出新问题。请务必在新问题中包含您正在讨论的代码。
  • 我在link提出了一个新问题
猜你喜欢
  • 1970-01-01
  • 2010-11-26
  • 2012-01-04
  • 1970-01-01
  • 1970-01-01
  • 2019-11-22
  • 2011-03-26
  • 2011-07-22
  • 1970-01-01
相关资源
最近更新 更多