Hallo,
ich habe ein Problem mit meinem aktuellen Programmversuch.
Ich habe mit dem TSB-Code (weiß nicht mehr von wo genau in diesem Forum hier) ein ToolStrip in die Fensterleiste gemacht. Ich habe nun zwei Probleme:
1. Wenn ich die Form maximiere, wird die Fenserleiste oben schwarz, wie es in Vista normalerweise ist.
Kann man das unter Win7 ändern?
2. Ich habe in der Form ein TableLayout drin. Wenn ich das nicht auf Dock = None stelle, kann ich das Fenster an den Seiten nicht mehr bewegen, da die Ränder vom TL überlagert werden.
Kann man das ändern?
Spoiler anzeigen
Wenn noch weitere Informationen benötigt werden, bitte einfach schreiben.
mbfan
ich habe ein Problem mit meinem aktuellen Programmversuch.
Ich habe mit dem TSB-Code (weiß nicht mehr von wo genau in diesem Forum hier) ein ToolStrip in die Fensterleiste gemacht. Ich habe nun zwei Probleme:
1. Wenn ich die Form maximiere, wird die Fenserleiste oben schwarz, wie es in Vista normalerweise ist.
Kann man das unter Win7 ändern?
2. Ich habe in der Form ein TableLayout drin. Wenn ich das nicht auf Dock = None stelle, kann ich das Fenster an den Seiten nicht mehr bewegen, da die Ränder vom TL überlagert werden.
Kann man das ändern?
Das Ergebnis
Mein TSB-Code in der Hauptform
Mein Code in der TSB.vb-Datei
VB.NET-Quellcode
- Public Class Hauptform
- Private Sub Hauptform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- #Region " TSB-Code "
- Private dwmMargins As Dwm.MARGINS
- Private _marginOk As Boolean
- Private _aeroEnabled As Boolean
- Public Sub New()
- If Environment.OSVersion.Version.Major >= 6 Then
- Dim enabled As Integer = 0
- Dim response As Integer = Dwm.DwmIsCompositionEnabled(enabled)
- _aeroEnabled = enabled = 1
- End If
- If _aeroEnabled = True Then
- SetStyle(ControlStyles.ResizeRedraw, True)
- InitializeComponent()
- ToolStrip1.Renderer = New NCARenderer()
- DoubleBuffered = True
- End If
- End Sub
- Public Shared Function LoWord(ByVal dwValue As Integer) As Integer
- Return dwValue And &HFFFF
- End Function
- Public Shared Function HiWord(ByVal dwValue As Integer) As Integer
- Return (dwValue >> 16) And &HFFFF
- End Function
- Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
- If _aeroEnabled = True Then
- ToolStrip1.MaximumSize = New Size(Width - 100 - ToolStrip1.Left, 0)
- End If
- End Sub
- Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
- If _aeroEnabled = True Then
- If dwmMargins.cyTopHeight < ToolStrip1.Bottom Then
- dwmMargins.cyTopHeight = ToolStrip1.Bottom
- End If
- Dwm.DwmExtendFrameIntoClientArea(Me.Handle, dwmMargins)
- 'ToolStripButton2.Visible = True
- Else
- 'ToolStripButton2.Visible = False
- End If
- End Sub
- Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
- If _aeroEnabled Then
- e.Graphics.Clear(Color.Transparent)
- e.Graphics.FillRectangle(SystemBrushes.ButtonFace, Rectangle.FromLTRB(dwmMargins.cxLeftWidth - 0, dwmMargins.cyTopHeight - 0, Width - dwmMargins.cxRightWidth - 0, Height - dwmMargins.cyBottomHeight - 0))
- Else
- e.Graphics.Clear(Color.FromArgb(&HC2, &HD9, &HF7))
- End If
- End Sub
- Protected Overrides Sub WndProc(ByRef m As Message)
- Dim WM_NCCALCSIZE As Integer = &H83
- Dim WM_NCHITTEST As Integer = &H84
- Dim result As IntPtr
- Dim dwmHandled As Integer = Dwm.DwmDefWindowProc(m.HWnd, m.Msg, m.WParam, m.LParam, result)
- If dwmHandled = 1 Then
- m.Result = result
- Return
- End If
- If m.Msg = WM_NCCALCSIZE AndAlso CInt(m.WParam) = 1 Then
- Dim nccsp As SIZE_PARAMS = CType(System.Runtime.InteropServices.Marshal.PtrToStructure(m.LParam, GetType(SIZE_PARAMS)), SIZE_PARAMS)
- nccsp.rect0.Top += 0
- nccsp.rect0.Bottom += 0
- nccsp.rect0.Left += 0
- nccsp.rect0.Right += 0
- If (Not _marginOk) Then
- dwmMargins.cyTopHeight = nccsp.rect2.Top - nccsp.rect1.Top
- dwmMargins.cxLeftWidth = nccsp.rect2.Left - nccsp.rect1.Left
- dwmMargins.cyBottomHeight = nccsp.rect1.Bottom - nccsp.rect2.Bottom
- dwmMargins.cxRightWidth = nccsp.rect1.Right - nccsp.rect2.Right
- _marginOk = True
- End If
- System.Runtime.InteropServices.Marshal.StructureToPtr(nccsp, m.LParam, False)
- m.Result = IntPtr.Zero
- ElseIf m.Msg = WM_NCHITTEST AndAlso CInt(m.Result) = 0 Then
- m.Result = HitTestNCA(m.HWnd, m.WParam, m.LParam)
- Else
- MyBase.WndProc(m)
- End If
- End Sub
- Private Function HitTestNCA(ByVal hwnd As IntPtr, ByVal wparam As IntPtr, ByVal lparam As IntPtr) As IntPtr
- Dim HTCLIENT As Integer = 1
- Dim HTCAPTION As Integer = 2
- Dim HTLEFT As Integer = 10
- Dim HTRIGHT As Integer = 11
- Dim HTTOP As Integer = 12
- Dim HTTOPLEFT As Integer = 13
- Dim HTTOPRIGHT As Integer = 14
- Dim HTBOTTOM As Integer = 15
- Dim HTBOTTOMLEFT As Integer = 16
- Dim HTBOTTOMRIGHT As Integer = 17
- Dim p As New Point(LoWord(CInt(lparam)), HiWord(CInt(lparam)))
- Dim topleft As Rectangle = RectangleToScreen(New Rectangle(0, 0, dwmMargins.cxLeftWidth, dwmMargins.cxLeftWidth))
- If topleft.Contains(p) Then
- Return New IntPtr(HTTOPLEFT)
- End If
- Dim topright As Rectangle = RectangleToScreen(New Rectangle(Width - dwmMargins.cxRightWidth, 0, dwmMargins.cxRightWidth, dwmMargins.cxRightWidth))
- If topright.Contains(p) Then
- Return New IntPtr(HTTOPRIGHT)
- End If
- Dim botleft As Rectangle = RectangleToScreen(New Rectangle(0, Height - dwmMargins.cyBottomHeight, dwmMargins.cxLeftWidth, dwmMargins.cyBottomHeight))
- If botleft.Contains(p) Then
- Return New IntPtr(HTBOTTOMLEFT)
- End If
- Dim botright As Rectangle = RectangleToScreen(New Rectangle(Width - dwmMargins.cxRightWidth, Height - dwmMargins.cyBottomHeight, dwmMargins.cxRightWidth, dwmMargins.cyBottomHeight))
- If botright.Contains(p) Then
- Return New IntPtr(HTBOTTOMRIGHT)
- End If
- Dim top As Rectangle = RectangleToScreen(New Rectangle(0, 0, Width, dwmMargins.cxLeftWidth))
- If top.Contains(p) Then
- Return New IntPtr(HTTOP)
- End If
- Dim cap As Rectangle = RectangleToScreen(New Rectangle(0, dwmMargins.cxLeftWidth, Width, dwmMargins.cyTopHeight - dwmMargins.cxLeftWidth))
- If cap.Contains(p) Then
- Return New IntPtr(HTCAPTION)
- End If
- Dim left As Rectangle = RectangleToScreen(New Rectangle(0, 0, dwmMargins.cxLeftWidth, Height))
- If left.Contains(p) Then
- Return New IntPtr(HTLEFT)
- End If
- Dim right As Rectangle = RectangleToScreen(New Rectangle(Width - dwmMargins.cxRightWidth, 0, dwmMargins.cxRightWidth, Height))
- If right.Contains(p) Then
- Return New IntPtr(HTRIGHT)
- End If
- Dim bottom As Rectangle = RectangleToScreen(New Rectangle(0, Height - dwmMargins.cyBottomHeight, Width, dwmMargins.cyBottomHeight))
- If bottom.Contains(p) Then
- Return New IntPtr(HTBOTTOM)
- End If
- Return New IntPtr(HTCLIENT)
- End Function
- #End Region
- End Class
VB.NET-Quellcode
- Option Explicit On
- Option Strict On
- Imports System.Runtime.InteropServices
- Imports System.Drawing.Drawing2D
- #Region "DWM"
- Public Class Dwm
- _
- Public Shared Function DwmDefWindowProc(ByVal hwnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr, ByRef result As IntPtr) As Integer
- End Function
- _
- Public Shared Function DwmIsCompositionEnabled(ByRef pfEnabled As Integer) As Integer
- End Function
- _
- Public Shared Function DwmExtendFrameIntoClientArea(ByVal hdc As IntPtr, ByRef marInset As MARGINS) As Integer
- End Function
- _
- Public Structure MARGINS
- Public cxLeftWidth As Integer
- Public cxRightWidth As Integer
- Public cyTopHeight As Integer
- Public cyBottomHeight As Integer
- Public Sub New(ByVal Left As Integer, ByVal Right As Integer, ByVal Top As Integer, ByVal Bottom As Integer)
- Me.cxLeftWidth = Left
- Me.cxRightWidth = Right
- Me.cyTopHeight = Top
- Me.cyBottomHeight = Bottom
- End Sub
- End Structure
- End Class
- #End Region
- #Region "NCARenderer"
- Public Class NCARenderer
- Inherits Office2007Renderer.Office2007Renderer
- Protected Overrides Sub OnRenderToolStripBackground(ByVal e As ToolStripRenderEventArgs)
- If e.ToolStrip.IsDropDown Then
- MyBase.OnRenderToolStripBackground(e)
- Else
- e.Graphics.Clear(Color.Transparent)
- End If
- End Sub
- Protected Overrides Sub OnRenderToolStripBorder(ByVal e As ToolStripRenderEventArgs)
- If e.ToolStrip.IsDropDown Then
- MyBase.OnRenderToolStripBorder(e)
- End If
- End Sub
- Protected Overrides Sub OnRenderItemText(ByVal e As ToolStripItemTextRenderEventArgs)
- If e.ToolStrip.IsDropDown Then
- MyBase.OnRenderItemText(e)
- Else
- Dim path As New GraphicsPath()
- path.AddString(e.Text, e.TextFont.FontFamily, CInt(Fix(e.TextFont.Style)), e.TextFont.Size + 2, e.TextRectangle.Location, New StringFormat())
- e.Graphics.SmoothingMode = SmoothingMode.HighQuality
- e.Graphics.FillPath(Brushes.Black, path)
- path.Dispose()
- End If
- End Sub
- Protected Overrides Sub OnRenderOverflowButtonBackground(ByVal e As ToolStripItemRenderEventArgs)
- If e.Item.Selected Then
- e.Graphics.Clear(Color.FromArgb(20, Color.Navy))
- End If
- Dim r As Rectangle = Rectangle.Empty
- If e.Item.RightToLeft = RightToLeft.Yes Then
- r = New Rectangle(0, e.Item.Height - 8, 9, 5)
- Else
- r = New Rectangle(e.Item.Width - 12, e.Item.Height - 16, 9, 5)
- End If
- MyBase.DrawArrow(New ToolStripArrowRenderEventArgs(e.Graphics, e.Item, r, SystemColors.ControlText, ArrowDirection.Down))
- e.Graphics.DrawLine(SystemPens.ControlText, CInt(Fix(r.Right - 7)), CInt(Fix(r.Y - 2)), CInt(Fix(r.Right - 3)), CInt(Fix(r.Y - 2)))
- End Sub
- End Class
- #End Region
- #Region "Api"
- _
- Public Structure RECT
- Public Left As Integer
- Public Top As Integer
- Public Right As Integer
- Public Bottom As Integer
- End Structure
- _
- Public Structure SIZE_PARAMS
- Public rect0, rect1, rect2 As RECT
- Public lppos As IntPtr
- End Structure
- #End Region
Wenn noch weitere Informationen benötigt werden, bitte einfach schreiben.
mbfan