繁体   English   中英

在Visual Studio 2015和Windows 10中无法获得XP样式按钮(FlatStyle = System)?

[英]Can't get XP style buttons (FlatStyle=System) in Visual Studio 2015 and Windows 10?

我已经尝试了很多解决方案,以使用每个按钮的FlatStyle = System以及在VB.NET上获得XP样式的按钮

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

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

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

Imports System.Windows.Forms.VisualStyles

Public Sub New()
     InitializeComponent()
     ' Add any initialization after the InitializeComponent() call.
     Application.VisualStyleState = VisualStyleState.NoneEnabled
End Sub

如果您想了解上述解决方案的正确性,那么您应该尝试查看下面的MSDN示例,我必须对其进行修改以使其运行。 首先,在VS中创建一个新项目,向其中添加一个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

在运行时,只需单击各种RadioButton,然后单击Button1,此后您将看到客户端(边界)和非客户端(内部控件)的更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM