【问题标题】:Can't get XP style buttons (FlatStyle=System) in Visual Studio 2015 and Windows 10?在 Visual Studio 2015 和 Windows 10 中无法获取 XP 样式按钮 (FlatStyle=System)?
【发布时间】:2017-05-28 07:12:24
【问题描述】:

我已经尝试了很多解决方案来在 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 风格的按钮?

【问题讨论】:

    标签: vb.net visual-studio windows-xp controls


    【解决方案1】:

    通过添加以下导入并修改 Form1 的构造函数(新子例程),我获得了在 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中新建一个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
    

    在运行时,只需单击各种 RadioButton,然后单击 Button1,然后您将看到客户端(边框)和非客户端(内部控件)发生变化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-27
      • 2015-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 2015-10-24
      • 1970-01-01
      相关资源
      最近更新 更多