向现有 Windows 窗体应用程序添加上下文相关帮助的好方法是什么?

发布于 2024-08-17 13:02:23 字数 397 浏览 3 评论 0原文

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

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

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

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

I have to add database-driven tooltips to an existing WinForms App, big one. C# and .NET 3.5

I'd like to avoid having to drop new controls for this, and the user has to be able to edit the help tooltips.

My best guess is to wrap the existing controls in a new type that contains new properties, so that I can assign a new property like "FieldHelpName", and can use that in the administrative module so the user can identify the field clearly. I'd assign a ScreenID to each form and each FieldHelpName record would be linked to a ScreenID. At application startup, load all the help contents, and on form-load, filter by its ScreenID and add the corresponding tooltips using reflection, most likely.

I'm looking for suggestions on how to do this process best or to know if there are any best practices on how to do this...so any help is really appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一影成城 2024-08-24 13:02:23

为什么要花这么长的篇幅呢?

您可以用更简单的方法来完成同样的事情:

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

Why go into such lengths?

You can accomplish the same thing with something simpler:

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
许久 2024-08-24 13:02:23

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

Ended up creating a database table for configuration and specifying control name for each row, and then looping screen controls recursively to add tooltips if the current control name matches the database record's control name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文