无论如何有一个按钮(btnHCon)点击事件,在vb.net中启用高对比度模式(然后显然是再次关闭它)?
我希望在将其添加到我的项目时添加功能/可访问性(类似于在控制面板中切换高对比度)?
任何建议都非常感谢!
无论如何有一个按钮(btnHCon)点击事件,在vb.net中启用高对比度模式(然后显然是再次关闭它)?
我希望在将其添加到我的项目时添加功能/可访问性(类似于在控制面板中切换高对比度)?
任何建议都非常感谢!
似乎做到这一点的唯一方法是在高对比度模式下为表单/控件使用系统默认颜色(因为只有那些会被高对比度模式更改)。1 要打开高对比度模式,您唯一的选择似乎是使用非托管代码——尤其是SystemParametersInfo()
带有结构 的.uiAction
SPI_SETHIGHCONTRAST
HIGHCONTRAST
pvParam
我不太擅长调用非托管代码,但幸运的是 VBForums 的 chris128 完成了艰苦的工作。不过,您只能靠自己来设置它!但我认为,如果您查看上面的参考资料,您可以找出适当的调整。
Imports System.Runtime.InteropServices
Public Class Form1
'
'API declarations
'
Public Const HCF_HIGHCONTRASTON As Integer = 1
Public Const SPI_SETHIGHCONTRAST As Integer = 67
Public Const SPIF_SENDWININICHANGE As Integer = 2
<System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)> _
Public Structure HIGHCONTRAST
Public cbSize As UInteger
Public dwFlags As UInteger
<System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Public lpszDefaultScheme As String
End Structure
<System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="SystemParametersInfoW")> _
Public Shared Function SystemParametersInfoW(ByVal uiAction As UInteger, ByVal uiParam As UInteger, ByVal pvParam As System.IntPtr, ByVal fWinIni As UInteger) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
End Function
'
'End of API declarations
'
'Some button click event
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim highcontraststruct As New HIGHCONTRAST
highcontraststruct.dwFlags = HCF_HIGHCONTRASTON
highcontraststruct.cbSize = CUInt(Marshal.SizeOf(highcontraststruct))
Dim highcontrastptr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(highcontraststruct))
Runtime.InteropServices.Marshal.StructureToPtr(highcontraststruct, highcontrastptr, False)
SystemParametersInfoW(SPI_SETHIGHCONTRAST, CUInt(Marshal.SizeOf(highcontraststruct)), highcontrastptr, SPIF_SENDWININICHANGE)
End Sub
End Class