Click here to Skip to main content
14,669,324 members
Rate this:
Please Sign up or sign in to vote.
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
       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
Posted
Updated 8-Jun-11 1:08am
v4

Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100