Click here to Skip to main content
15,122,559 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
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
   End Sub

   Protected Overloads Overrides Sub OnResize(ByVal eventargs As System.EventArgs)

   End Sub

   Protected Overloads Overrides Sub OnControlAdded(ByVal e As ControlEventArgs)
   End Sub

   Protected Overloads Overrides Sub OnScroll(ByVal e As ScrollEventArgs)
   End Sub

Methods overriden:
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
      If (m.Msg = WM_NCPAINT) Then
      ElseIf (m.Msg = WM_PAINT) Then
      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)
                   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)
                   CombineRgn(hRgn1, hRgn1, hRgn2, RGN_AND)
               End If
           End Using
       End If
       msg.Result = CType(1, IntPtr)
       ReleaseDC(msg.HWnd, hdc)
   End Sub
Updated 8-Jun-11 2:08am

Possibly some thing is broken in inherited class.

Have a look into the events that you have overridden, this will be most likely cause for the problem.

Put your code here, so that some one will be able to help you.
R u working in TCS ?? you are from west godavari bheemavaram?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900