【发布时间】:2021-10-04 15:23:14
【问题描述】:
我已经阅读了几个论坛并尝试了不同的选项。大多数答案都是this,这让我认为这就是问题所在。我放了Application.EnableVisualStyles()
.Designer.vb 文件中InitializeComponent() 的开头,如下所示:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class MetadataCollectionGUI
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Application.EnableVisualStyles() ' <--- See Here
Me.ListViewMetaDataCollection = New System.Windows.Forms.ListView()
Me.ColumnTags = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
etc... etc...
End Sub
Etc...
End Class
我是否误解了如何执行该特定解决方案,或者问题是否有所不同?
【问题讨论】:
-
认为您需要将其移到调用堆栈的某个位置。如链接中所述,它通常在您的应用程序主中首先完成。在这样的形式里面可能为时已晚
-
首先,正如评论所述,您不应该编辑
InitializeComponent方法。除非您实际上修复了设计者应该自己完成的事情,否则下次您在设计器中进行更改时,您所做的任何手动代码更改都将丢失。 -
另外,无论如何,您尝试做的事情毫无意义。您提供的链接适用于 C#,您始终需要自己的
Main方法。在 VB 项目中,应用程序框架默认启用,它在自动生成的代码中对您隐藏Main方法,并且默认情况下也启用视觉样式。查看您的项目属性并在其中启用视觉样式(如果当前未启用)。如果它们已经存在,那么您正在尝试解决一个不存在的问题。请添加您的ListView的屏幕截图,以便我们查看是否启用了视觉样式。 -
啊,谢谢@jmcilhinney。我不知道 C# 与 VB 有什么不同。我边走边学,所以我不知道 VB 隐藏了
Main方法。我只是假设由于我的项目以我的表单启动并且我无法找到Main,所以它根本不存在。我不确定ListView的屏幕截图是什么意思。您需要查看属性窗口、.designer.vb 代码还是 GUI?提前致谢! -
我们现在不需要看到任何东西,但我的意思是运行时控件的屏幕截图。如果我们可以看到控件,我们就可以判断视觉样式是否已启用。
标签: vb.net winforms .net-framework-4.8 listviewgroup