【发布时间】:2020-01-27 00:42:46
【问题描述】:
我正在尝试创建一个用户控件,该控件将修改模板生成的一些源代码。
我已尝试从我创建的自定义 ControlDesign 中获取程序集位置,但这是 Visual Studio .exe 位置,而不是源代码位置。
Private Designer As BulkOpsVesselGridControlDesigner
Public Sub New(ByVal Designer As BulkOpsVesselGridControlDesigner)
MyBase.New(Designer.Component)
Me.Designer = Designer
End Sub
Public Property GridType() As BulkOpsGrids
Get
Return Me.Designer.VesselGridControl.GridType
End Get
Set(ByVal value As BulkOpsGrids)
Me.Designer.VesselGridControl.GridType = value
If value = BulkOpsGrids.NewGrid Then
'Display Input from Developer
Dim gridName = InputBox("Please Type out the name of the Grid Type Without Spaces. Ex: WorkingCrane")
'TODO: Get file path programmatically (based on developer)
Dim path = "C:\BulkOpsWinUILib\UserControls\GridPropertyData\BulkOpsGridData.vb"
Dim fileExists As Boolean = IO.File.Exists(path)
Using sw As New IO.StreamWriter(IO.File.Open(path, IO.FileMode.OpenOrCreate))
'TODO: write logic for formatting and proper placedment
sw.WriteLine(gridName)
End Using
End If
End Set
End Property
最终,如果开发人员选择“newGrid”选项,我希望它自动提示网格定义的详细信息,然后将该选项添加到正确的源代码中。
希望创建一个模板,用于帮助标准化我们在未来应用程序中构建这些控件的方式。模板本身将帮助根据需要创建和构建源代码。类似于设计器如何自动写入 .designer 文件。
【问题讨论】:
标签: vb.net visual-studio custom-controls designer