在 vb.net 中制作 Windows 窗体应用程序时,我遇到了这个错误:
System.OverflowException: '算术运算导致溢出。'
我的代码:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("dwmapi.dll")>
Private Shared Sub DwmGetColorizationColor(ByRef ColorizationColor As UInteger, ByRef ColorizationOpaqueBlend As Boolean)
End Sub
Private Function UintToColor(ByVal argb As UInteger)
Dim a = argb >> 24
Dim r = argb >> 16
Dim g = argb >> 8
Dim b = argb >> 0
Return Color.FromArgb(a, r, g, b)
End Function
Dim windowColor
Dim windowBlend
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Show()
DwmGetColorizationColor(windowColor, windowBlend)
Me.BackColor = UintToColor(windowColor)
End Sub
End Class
该函数返回(来自“autos”):
a: 227
r: 55182
g: 14876783
b: 3808456647
argb:3808456647
我认为您正试图将 uint 拆分为字节大小的块。
也许试试这个
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("dwmapi.dll")>
Private Shared Sub DwmGetColorizationColor(ByRef ColorizationColor As UInteger, ByRef ColorizationOpaqueBlend As Boolean)
End Sub
Private Function UintToColor(ByVal argb As UInteger)
Dim bytes As Byte() = BitConverter.GetBytes(argb)
Dim b = bytes(0)
Dim g = bytes(1)
Dim r = bytes(2)
Dim a = bytes(3)
Dim result As Color = Color.FromArgb(a, r, g, b)
Return result
End Function
Dim windowColor
Dim windowBlend
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Show()
DwmGetColorizationColor(windowColor, windowBlend)
Me.BackColor = UintToColor(windowColor)
End Sub
End Class
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句