小编DRo*_*oam的帖子

VB.NET:通过将处理程序函数指定为变量来实现“AddHandler”

我正在为 Autodesk Inventor(一个 3D CAD 程序)编写一个插件。该插件向 Inventor 添加了一系列内部命令,并为每个命令创建了一个工具栏按钮。我需要将每个命令的 Execute 事件连接到加载项中的处理程序函数。

我创建了一个“MyCommand”类,其中包含定义命令所需的所有信息。我还创建了一个 List(Of MyCommand) ,其中包含每个命令的定义。最后,我可以遍历每个命令并创建内部 Inventor 命令定义,以及将按钮添加到工具栏。但是,我不知道该怎么做是将命令与其 Handler 函数在 loop 内关联起来。

下面的示例代码说明了我所追求的:

Sub CreateCommands()
    Dim oCommands As New List(Of MyCommand)

    oCommands.Add(New MyCommand("DrawLogoCmd", "Draw Logo", "DrawLogoSub"))
    oCommands.Add(New MyCommand("PublishDrawingCmd", "Publish Drawing", "PublishDrawingSub"))
    ' [Dozens more commands]

    For Each oCommand As MyCommand In oCommands
        ' Code for adding internal command definition and button to Inventor. This is working fine.
        Dim oCommandDef As Inventor.CommandDefinition = InventorApp.CommandDefinitions.Add(oCommand.InternalDefinitionName, oCommand.DisplayName)
        InventorApp.ToolbarButtons.Add(oCommandDef)

        ' Associate command definition with …
Run Code Online (Sandbox Code Playgroud)

vb.net event-handling

3
推荐指数
1
解决办法
860
查看次数

Visual Studio:仅对少数几行覆盖“智能”缩进

我在Visual Studio中编写一些vb.net代码。我已经启用了智能缩进功能,并且希望继续启用它。但是,我的代码中有一部分我想使用一些额外的缩进以更易于理解的方式概述事物。我可以跳到所需的缩进级别,但是一旦我切换到另一行,智能缩进就会将该行推回到“应该”的位置。

如何在不完全禁用智能缩进的情况下向代码中的某些行添加一些额外的缩进?


我要的是:

Call GetRibbon("Part")
     Call GetTab("3D Model")
          Call NewButton("Custom1")
Call GetRibbon("Assembly")
     Call GetTab("Assemble")
          Call NewButton("Custom2")
Run Code Online (Sandbox Code Playgroud)

VS如何格式化:

Call GetRibbon("Part")
Call GetTab("3D Model")
Call NewButton("Custom1")
Call GetRibbon("Assembly")
Call GetTab("Assemble")
Call NewButton("Custom2")
Run Code Online (Sandbox Code Playgroud)

vb.net tabs indentation visual-studio

2
推荐指数
1
解决办法
41
查看次数

Visual Studio:刷新“查找所有引用”结果

Find All References 工具非常有用,但我经常发现自己希望能够刷新结果,例如:

  • 在更改列出的其中一行之后,它不再引用我所做的“查找所有引用”。
  • 添加或删除一些代码行后,这会弄乱“查找所有引用”窗口的“双击转到行”功能。

据我所知,没有办法刷新结果,但我觉得这很难相信。我是忽略了什么还是这真的是一个缺失的功能?

我知道我可以去某个方法/变量/等的地方。使用时,右键单击它,然后再次执行“查找所有引用”,但这比单击“刷新”按钮要乏味得多。

visual-studio

2
推荐指数
1
解决办法
244
查看次数