我已经尝试了很多解决方案,在VB.NET上使用FlatStyle = System为每个按钮获取XP风格的按钮以及使用
Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New Form1())
End Sub
在Form1类中,但它不起作用。我所能做的就是假设我无法获得XP风格的按钮,因为我的Windows 10设置不合适 - 因为MSDN页面声明对于FlatStyle = System,控件的外观采用了操作系统设置。因此,在Windows 10中使用VS 2015必须做什么才能获得XP风格的按钮?
答案 0 :(得分:0)
通过添加以下Imports并修改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
在运行时,只需单击各种RadioButtons,然后单击Button1,您将看到客户端(边框)和非客户端(内部控件)此后发生更改。