Hallo, ich habe folgenden Code für eine Appbar:
Spoiler anzeigen
aber leider funktioniert es nur mit Formborderstyle = toolwindow richtig wenn ich None verwnde schaut das so aus (das graue ganz oben ist die app bar und die ist an der falschen position. eigentlich sollte alles dort oben über dem Fenster grau sein.) :
VB.NET-Quellcode
- Imports System.Runtime.InteropServices
- Public Class AppBar
- ''' <sumary>
- ''' Beinhaltet Information über die Application Bar.
- ''' Eine ausführliche Beschreibung finden Sie in MSDN APPBARDATA Dokumentation.
- ''' </sumary>
- <StructLayout(LayoutKind.Sequential)> _
- Public Structure APPBARDATA
- Public cbSize As UInteger
- Public hWnd As IntPtr
- Public uCallbackMessage As UInteger
- Public uEdge As UInteger
- Public rc As RECT
- Public lParam As Integer
- End Structure
- ''' <sumary>
- ''' Speichert Größe und Position der AppBAr.
- ''' </sumary>
- <StructLayout(LayoutKind.Sequential)> _
- Public Structure RECT
- Public left As Integer
- Public top As Integer
- Public right As Integer
- Public bottom As Integer
- End Structure
- <DllImport("shell32.dll")> _
- Private Shared Function SHAppBarMessage(ByVal dwMessage As UInteger, ByRef pData As APPBARDATA) As IntPtr
- End Function
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Private Shared Function RegisterWindowMessage(ByVal lpString As String) As UInteger
- End Function
- Const ABM_NEW As Integer = &H0
- Const ABM_REMOVE As Integer = &H1
- Const ABM_SETPOS As Integer = &H3
- Const ABM_QUERYPOS As Integer = &H2
- Const ABE_TOP As Integer = 1
- Private Sub AppBar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'Me.Location = New Point(0, 0)
- ' Datenstruktur für AppBar erzeugen und initialisieren.
- Dim abd As New APPBARDATA()
- abd.cbSize = CUInt(Marshal.SizeOf(GetType(APPBARDATA)))
- abd.hWnd = Me.Handle
- abd.uCallbackMessage = RegisterWindowMessage(Guid.NewGuid().ToString())
- ' AppBar beim System registrieren.
- SHAppBarMessage(ABM_NEW, abd)
- ' Größe und Position festlegen.
- ' In dem Beispiel wird oben am Desktop 100 Pixel Platz reserviert.
- abd.rc = New RECT()
- abd.uEdge = ABE_TOP
- abd.rc.top = 0
- abd.rc.left = 0 ' - 100
- abd.rc.bottom = 100 'SystemInformation.PrimaryMonitorSize.Height
- abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
- ' Die Gröse und Position der AppBar prüfen.
- ' Wenn diese nicht gültig sind, werden die
- ' korrigierte Werte zurückgegeben.
- SHAppBarMessage(ABM_QUERYPOS, abd)
- ' Größe und Position der AppBarsetzen
- SHAppBarMessage(ABM_SETPOS, abd)
- ' Größe und Position des Anwendungsfenster im AppBar Bereich positionieren
- Location = New Point(abd.rc.left, abd.rc.top)
- Size = New Size(abd.rc.right, abd.rc.bottom)
- Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
- End Sub
- Private Sub AppBar_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
- Dim abd As New APPBARDATA()
- abd.cbSize = CUInt(Marshal.SizeOf(GetType(APPBARDATA)))
- abd.hWnd = Me.Handle
- SHAppBarMessage(ABM_REMOVE, abd)
- MyBase.OnClosed(e)
- End Sub
- End Class
aber leider funktioniert es nur mit Formborderstyle = toolwindow richtig wenn ich None verwnde schaut das so aus (das graue ganz oben ist die app bar und die ist an der falschen position. eigentlich sollte alles dort oben über dem Fenster grau sein.) :
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „MAAN10“ ()