.NET PowerPacks RectangleShape flickers on form resize

自古美人都是妖i 提交于 2019-12-12 06:23:37

问题


I can do something as simple as:

  1. Create a new .NET form application
  2. Put a single RectangleShape onto the form
  3. add the following into the InitializeComponent method in the designer code

    Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or _
        ControlStyles.UserPaint Or _
        ControlStyles.DoubleBuffer, True)
    Me.UpdateStyles()
    
  4. Run the program
  5. Resize the form
  6. Watch angrily as the rectangle flickers

Is it possible to get rid of this? Or is the ShapeContainer internally flawed and I need to find a different solution?


回答1:


It's fairly flawed. It uses its own window that's overlaid onto the form with the WS_EX_TRANSPARENT style turned on. That style makes it invisible, but also prevents any kind of double-buffering from working properly. Double-buffering the form has no effect, wrong window.

It is otherwise a rather expensive way to draw shapes. The cheap and flicker-free way is using e.Graphics.FillRectangle() in the form's OnPaint() override or Paint event handler.




回答2:


I've never used the ShapeContainer but when ever I do custom graphics like that, I create a subclass for a Panel and in the constructor of my subclass I set DoubleBuffered to true.

More specific code example here.



来源:https://stackoverflow.com/questions/6585973/net-powerpacks-rectangleshape-flickers-on-form-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!