Hi Leute
Die Schleife hab ich jetzt geschrieben, was an sich kein Problem war, aber wie es wohl immer so ist, löst ein Problem das Andere ab.
Public Class Form1
Private mMargins() As MARGINS
Private mControls() As Control
<StructLayout(LayoutKind.Sequential)> _
Public Structure MARGINS
Public LeftWidth As Integer
Public RightWidth As Integer
Public TopHeight As Integer
Public BottomHeight As Integer
End Structure
<DllImport("dwmapi.dll")> _
Public Shared Function DwmExtendFrameIntoClientArea(ByVal hWnd As IntPtr, _
ByRef marginset As MARGINS) As Integer
End Function
<DllImport("dwmapi.dll", PreserveSig:=False)> _
Public Shared Function DwmIsCompositionEnabled() As Boolean
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Array.Resize(mControls, 3)
Array.Resize(mMargins, mControls.Length)
Me.mControls(0) = ListView1
Me.mControls(1) = ListView2
Me.mControls(2) = Button1
End Sub
Protected Overloads Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
If DwmIsCompositionEnabled() Then
For i As Integer = 0 To mControls.Length - 1
With mControls(i)
mMargins(i) = New MARGINS()
mMargins(i).LeftWidth = .Location.X
mMargins(i).RightWidth = Me.Width - .Location.X - _
.Size.Width - 25
mMargins(i).TopHeight = .Location.Y
mMargins(i).BottomHeight = Me.Height - .Location.Y - _
.Size.Height - 45
End With
Next
'Hier ist das Problem
DwmExtendFrameIntoClientArea(Me.Handle, mMargins(0))
End If
End Sub
Protected Overloads Overrides Sub OnPaintBackground(ByVal e As _
PaintEventArgs)
MyBase.OnPaint(e)
If DwmIsCompositionEnabled() Then
Dim clientArea() As Rectangle
e.Graphics.Clear(Color.Black)
Array.Resize(clientArea, mMargins.Length)
For i As Integer = 0 To mMargins.Length - 1
With Me.mMargins(i)
clientArea(i) = New Rectangle(.LeftWidth, .TopHeight, _
Me.ClientRectangle.Width - .LeftWidth - .RightWidth, _
Me.ClientRectangle.Height - .TopHeight - .BottomHeight)
End With
Next
Dim b As Brush = New SolidBrush(Me.BackColor)
e.Graphics.FillRectangles(b, clientArea)
End If
End Sub
End ClassDas Ergebnis sieht dann so aus:
Ich habe die Size des Feldes um 10 vergrößert, um es besser zu verdeutlichen.
Wie man sieht, zeichnet DwmExtendFrameIntoClientArea nur ein Feld korrekt.
Wenn ich den Parameter marginset auf marginset() verändere und nur mMargin übergebe, zeichnet er gar kein Feld ordentlich.
Ich muss anfügen, dass ich nicht wirklich Ahnung von APIs habe und erst recht nicht vom Desktop Window Manager.
Vielleicht kennt ja jemand eine Funkiton aus der dwmapi, welche mehrere Felder zeichnet.
schönen Sonntag noch
Maas |