Click here to Skip to main content
15,891,136 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 :
VB
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:
VB
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


VB
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
Posted
Updated 8-Jun-11 1:08am
v4

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.
 
Share this answer
 
R u working in TCS ?? you are from west godavari bheemavaram?
 
Share this answer
 

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