【问题标题】:Good way to add context-sensitive help to an existing Windows Forms application?向现有 Windows 窗体应用程序添加上下文相关帮助的好方法?
【发布时间】:2010-01-10 16:38:32
【问题描述】:

我必须将数据库驱动的工具提示添加到现有的 WinForms 应用程序,大一个。 C# 和 .NET 3.5

我希望避免为此删除新控件,并且用户必须能够编辑帮助工具提示。

我最好的猜测是将现有控件包装在包含新属性的新类型中,以便我可以分配一个新属性,如“FieldHelpName”,并可以在管理模块中使用它,以便用户可以清楚地识别该字段.我会为每个表单分配一个 ScreenID,每个 FieldHelpName 记录将链接到一个 ScreenID。在应用程序启动时,加载所有帮助内容,在表单加载时,通过其 ScreenID 过滤并使用反射添加相应的工具提示。

我正在寻找有关如何最好地执行此过程的建议,或者想知道是否有任何关于如何执行此操作的最佳实践......所以非常感谢任何帮助。谢谢。

【问题讨论】:

  • 什么是编程语言C#/VB.Net/...? .NET 框架版本是什么?
  • 啊,谢谢 Zyphrax,忘记说明了。已编辑问题

标签: c# winforms context-sensitive-help


【解决方案1】:

为什么要这么长?

你可以用更简单的东西来完成同样的事情:

Private _ToolTipList As New List(Of ToolTip)

<Extension()> _
Public Function CreateForm(ByVal formType As Type) As Form
  If (formType Is Nothing) Then
    Throw New ArgumentNullException("formType")
  End If
  If (Not GetType(Form).IsAssignableFrom(formType)) Then
    Throw New InvalidOperationException _
        (String.Format("The type '{0}' is not a form.", formType.FullName))
  End If

  Dim ctor = formType.GetConstructor(New Type() {})
  If (ctor Is Nothing) Then
    Throw New InvalidOperationException _
        (String.Format _
            ("The type '{0}' does not have a public default constructor.", _
            formType.FullName))
  End If

  Dim frm As Form = ctor.Invoke(New Object() {})
  Dim toolTip As New ToolTip(New Container())
  LoadToolTipData(toolTip, frm)
  _ToolTipList.Add(toolTip)

  Return frm

End Function

Private Sub LoadToolTipData(ByVal toolTip As ToolTip, _
                            ByVal ctrl As Control, _
                   Optional ByVal parentHierarchy As String = "")

  Dim currentHierarchy = parentHierarchy & "." & ctrl.Name
  Dim toolTipText = LoadDataFromDb(currentHierarchy)
  If Not String.IsNullOrEmpty(toolTipText) Then
    toolTip.SetToolTip(ctrl, toolTipText)
  End If

  For Each c As Control In ctrl.Controls
    LoadToolTipData(toolTip, c, currentHierarchy)
  Next

End Sub

Private Function LoadDataFromDb(ByVal key As String) As String
  Return String.Empty
End Function

【讨论】:

  • Paulo...这意味着我会让用户根据控件 ID 猜测字段名称,这在大多数情况下并不明显。
  • 如果您要添加有关每个控件的信息,您可以在数据库中指定一个显示名称,并让用户提供有关管理应用程序的帮助信息。
【解决方案2】:

最终创建了一个用于配置的数据库表并为每一行指定控件名称,然后如果当前控件名称与数据库记录的控件名称匹配,则递归循环屏幕控件以添加工具提示。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    • 2013-08-01
    相关资源
    最近更新 更多