hi guys i write a custom title bar with wndproc (form is sizable tool box because it haves rectangle shape)
but theres 2 errors we cant click the close button i draw with visualstyles and sometimes title bar or close button (real one) appears
Code:
<DllImport("user32.dll")>
Private Shared Function GetWindowsRect(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
End Function
<DllImport("user32.dll")>
Private Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
End Function
<DllImport("User32.dll")>
Private Shared Function GetWindowDC(ByVal hWnd As IntPtr) As IntPtr
End Function
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Const WM_NCPAINT As Integer = 133
MyBase.WndProc(m)
If m.Msg = WM_NCPAINT Then
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
If CInt(hdc) <> 0 Then
Dim brushy As Brush
brushy = New Drawing.SolidBrush(Color.FromArgb(120, 197, 87))
Dim g As Graphics = Graphics.FromHdc(hdc)
Dim screenRectangle As Rectangle = RectangleToScreen(Me.ClientRectangle)
Dim titleHeight As Integer = screenRectangle.Top - Me.Top
Dim rect As Rectangle = New Rectangle(0, 0, Me.Width, 30)
Dim rectx As Rectangle = New Rectangle(Me.Width - 18, 10, 10, 10)
Dim text As Rectangle = New Rectangle(5, 5, Me.Width, 30)
g.FillRectangle(brushy, rect)
g.FillRectangle(Brushes.Red, rectx)
Dim drawFont As New System.Drawing.Font("and", 14)
g.DrawString("androidify PRO", drawFont, Brushes.White, text)
Dim r As New VisualStyles.VisualStyleRenderer(VisualStyles.VisualStyleElement.Window.MdiCloseButton.Normal)
r.DrawBackground(g, New Rectangle(Me.Width - 30, 0, 30, 30))
g.Flush()
ReleaseDC(m.HWnd, hdc)
End If
End If
End Sub