Vb.net Can';在Visual Studio 2015和Windows 10中,是否无法获得XP样式的按钮(FlatStyle=System)?

Vb.net Can';在Visual Studio 2015和Windows 10中,是否无法获得XP样式的按钮(FlatStyle=System)?,vb.net,visual-studio,windows-xp,controls,Vb.net,Visual Studio,Windows Xp,Controls,我已经尝试了很多解决方案,在VB.NET上使用FlatStyle=System和 Shared Sub Main() Application.EnableVisualStyles() Application.Run(New Form1()) End Sub 在Form1类中,但它不起作用。我所能做的就是假设我无法获得XP样式的按钮,因为我的Windows 10设置不合适——因为MSDN页面声明,对于FlatStyle=System,控件的外观采用操作系统设置。因此,使用VS 2

我已经尝试了很多解决方案,在VB.NET上使用FlatStyle=System和

Shared Sub Main()
    Application.EnableVisualStyles()
    Application.Run(New Form1())
End Sub

在Form1类中,但它不起作用。我所能做的就是假设我无法获得XP样式的按钮,因为我的Windows 10设置不合适——因为MSDN页面声明,对于FlatStyle=System,控件的外观采用操作系统设置。因此,使用VS 2015在Windows 10中必须做什么才能获得XP样式按钮?

我通过添加以下导入并修改Form1的构造函数(新的子例程),使XP样式在Windows 10和Visual Studio 2015中工作:

Imports System.Windows.Forms.VisualStyles

Public Sub New()
     InitializeComponent()
     ' Add any initialization after the InitializeComponent() call.
     Application.VisualStyleState = VisualStyleState.NoneEnabled
End Sub
如果您想了解为什么上面的解决方案是这样的,那么您应该尝试查看下面的MSDN示例,我必须对其进行修改以使其运行。首先,在VS make new Project中,向其中添加Form1,然后将以下所有代码粘贴到Form1的代码中:

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.VisualStyles
Public Class Form1
    Inherits Form
    Private WithEvents button1 As New Button()
    Private radioButton1 As New RadioButton()
    Private radioButton2 As New RadioButton()
    Private radioButton3 As New RadioButton()
    Private radioButton4 As New RadioButton()

    Public Sub New()
        With button1
            .AutoSize = True
            .Location = New Point(10, 10)
            .Text = "Update VisualStyleState"
        End With

        With radioButton1
            .Location = New Point(10, 50)
            .AutoSize = True
            .Text = "Apply styles to client area only"
        End With

        With radioButton2
            .Location = New Point(10, 70)
            .AutoSize = True
            .Text = "Apply styles to nonclient area only"
        End With

        With radioButton3
            .Location = New Point(10, 90)
            .AutoSize = True
            .Text = "Apply styles to client and nonclient areas"
        End With

        With radioButton4
            .Location = New Point(10, 110)
            .AutoSize = True
            .Text = "Disable styles in all areas"
        End With

        Me.Text = "VisualStyleState Test"
        Me.Controls.AddRange(New Control() {button1, radioButton1,
                radioButton2, radioButton3, radioButton4})
    End Sub

    <STAThread()>
    Shared Sub Main()
        Application.EnableVisualStyles()
        Application.Run(New Form1())
    End Sub

    Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
            Handles button1.Click

        If radioButton1.Checked Then
            Application.VisualStyleState =
                    VisualStyleState.ClientAreaEnabled
        ElseIf radioButton2.Checked Then
            Application.VisualStyleState =
                    VisualStyleState.NonClientAreaEnabled
        ElseIf radioButton3.Checked Then
            Application.VisualStyleState =
                    VisualStyleState.ClientAndNonClientAreasEnabled
        ElseIf radioButton4.Checked Then
            Application.VisualStyleState =
                    VisualStyleState.NoneEnabled
        End If

        ' Repaint the form and all child controls.
        Me.Invalidate(True)
    End Sub
导入系统
导入系统。绘图
导入System.Windows.Forms
导入System.Windows.Forms.VisualStyles
公开课表格1
继承形式
Private WithEvents按钮1作为新按钮()
专用radioButton1作为新RadioButton()
专用radioButton2作为新RadioButton()
专用radioButton3作为新RadioButton()
专用radioButton4作为新RadioButton()
公共分新()
带按钮1
.AutoSize=True
.位置=新点(10,10)
.Text=“更新VisualStyleState”
以
用无线电按钮1
.位置=新点(10,50)
.AutoSize=True
.Text=“仅将样式应用于客户端区域”
以
用无线电按钮2
.位置=新点(10,70)
.AutoSize=True
.Text=“仅将样式应用于非客户端区域”
以
带收音机按钮3
.位置=新点(10,90)
.AutoSize=True
.Text=“将样式应用于客户端和非客户端区域”
以
带收音机按钮4
.位置=新点(10110)
.AutoSize=True
.Text=“禁用所有区域中的样式”
以
Me.Text=“VisualStyleState测试”
Me.Controls.AddRange(新控件(){button1,radioButton1,
radioButton2、radioButton3、radioButton4})
端接头
共享子主目录()
Application.EnableVisualStyles()
Application.Run(新Form1())
端接头
子按钮1\u单击(ByVal发送者作为对象,ByVal e作为事件参数)_
手柄按钮1。单击
如果radioButton1.已检查,则
Application.VisualStyleState=
VisualStyleState.ClientAreaEnabled
ElseIf radioButton2.然后检查
Application.VisualStyleState=
VisualStyleState.nonClient已启用
ElseIf Radio按钮3.然后检查
Application.VisualStyleState=
VisualStyleState.ClientAndNonClientAreasEnabled
ElseIf Radio按钮4.然后检查
Application.VisualStyleState=
VisualStyleState.noEnabled
如果结束
'重新绘制窗体和所有子控件。
使无效(真)
端接头
在运行时,只需单击各种单选按钮,然后单击按钮1,您将看到客户机(边框)和非客户机(内部控件)随后发生更改