继承/派生面板的自动滚动无法正常工作 [英] AutoScroll of inherited/derived panel is not functioning properly

查看:84
本文介绍了继承/派生面板的自动滚动无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我设计了一个自定义面板,该面板继承自Windows面板控件.
我已将自定义面板的autoscroll属性设置为true.但是问题是垂直滚动条无法正确显示(有时滚动条箭头无法绘制,有时滚动条无法正确绘制)
如何解决这个问题?请帮帮我.

此自定义面板的目的是自定义面板的边框颜色.

我的代码中覆盖的事件是:

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

推荐答案

在继承的类中可能发生了某些事情.

查看您已覆盖的事件,这很可能是问题的原因.
将您的代码放在这里,以便有人可以为您提供帮助.
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.


在TCS中工作?你是来自西部戈达瓦里州的贝马瓦拉姆?
R u working in TCS ?? you are from west godavari bheemavaram?


这篇关于继承/派生面板的自动滚动无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆