Hi
i have designed a custom panel which is inherited from windows panel control.
i have set autoscroll property of custom panel to true.but the problem is vertical scrollbar not appearing properly(some times scrollbar arrows not painting and sometimes bar is not painting properly)
How to resolve this problem? please help me.
purpose of this custom panel is to customize the border colour of a panel.
events overridden in my code are :
Protected Overloads Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim g As Graphics = e.Graphics
g.SmoothingMode = SmoothingMode.AntiAlias
If (BackColor <> Color.Empty) Then
g.FillRectangle(New SolidBrush(Me.BackColor), Me.ClientRectangle)
End If
MyBase.OnPaint(e)
End Sub
Protected Overloads Overrides Sub OnResize(ByVal eventargs As System.EventArgs)
MyBase.OnResize(eventargs)
End Sub
Protected Overloads Overrides Sub OnControlAdded(ByVal e As ControlEventArgs)
MyBase.OnControlAdded(e)
End Sub
Protected Overloads Overrides Sub OnScroll(ByVal e As ScrollEventArgs)
MyBase.OnScroll(e)
End Sub
Methods overriden:
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
If (m.Msg = WM_NCPAINT) Then
Me.DrawNCBorder(m)
ElseIf (m.Msg = WM_PAINT) Then
Me.DrawNCBorder(m)
MyBase.WndProc(m)
Else
MyBase.WndProc(m)
End If
End Sub
Private Sub DrawNCBorder(ByRef msg As Message)
Dim hRgn1 As IntPtr = CType(msg.WParam, IntPtr)
Dim hdc As IntPtr = GetDCEx(msg.HWnd, hRgn1, DCX_WINDOW Or DCX_PARENTCLIP)
If (hdc <> IntPtr.Zero) Then
Using g As Graphics = Graphics.FromHdc(hdc)
Dim bounds As Rectangle = New Rectangle(0, 0, Me.Width, Me.Height)
If ((Me.Visible) And (Me.BorderStyle = BorderStyle.FixedSingle)) Then
ControlPaint.DrawBorder(g, bounds, Me.BorderColor, ButtonBorderStyle.Solid)
Else
ControlPaint.DrawBorder(g, bounds, Me.BackColor, ButtonBorderStyle.Solid)
End If
bounds.Inflate(-1, -1)
Dim hRgn2 As IntPtr = CreateRectRgn(bounds.Left, bounds.Top, bounds.Right, bounds.Bottom)
If (hRgn2 = CType(1, IntPtr)) Then
msg.WParam = CType(hRgn2, IntPtr)
Else
CombineRgn(hRgn1, hRgn1, hRgn2, RGN_AND)
DeleteObject(hRgn2)
End If
End Using
End If
msg.Result = CType(1, IntPtr)
ReleaseDC(msg.HWnd, hdc)
End Sub