locked
Custom Controls with transparencies RRS feed

  • Question

  • [Sorry for cross postage]

    Platform: Windows Mobile 6 Classic / .NET CF 3.5
    Problem: Custom Controls, that display alphablended images do not behave well with images on Parent control. Also, hidding and show such controls induces flicker when parent has many images to redraw.
    Details: A custom button Control that displays an image with transparencies. I use Alphablend function to achieve this with limited success. The parent is also a custom control and has a dimension of 320x240. This parent control also displays a background image. Both parent and child controls, are shown at same time. However, the custom button control can be hidden and shown. There is problem with showing and hiding child button; it's artifact remains and it flickers. In an attempt to reduce flicker the standard code is implemented in both child and parent custom controls;

    protected virtual void OnPaintBackground(PaintEventArgs e) {
          /* override prevents fliciker */ 
      }

    Its effectiveness is minimal at best. I need a way that Button control can erase itself without invoking repaint of parent. The  BitBlt function could work but experimentation showed that since Custom Button inherits from `System.Windows.Forms.Controls` the parent and child draw regions are treated as separate entities. Thus, draw region of Button will clobbers, not blended into, draw region of parent.

    My Question: How to blend images in the draw regions of one or more child controin, that must respond indendently to mouse events, with images in draw region of parent control? Also have child controls erase themselves, restoring parent control background, without invoking redraw of parent and it's other children? 

    ----------
    See example images and sample screenshot at:
    [Button.png] http://home.comcast.net/~mobi.apps.dev/button.png
    [Background.png] http://home.comcast.net/~mobi.apps.dev/background.png
    [Screen.png] http://home.comcast.net/~mobi.apps.dev/screen.png

    Thursday, August 6, 2009 6:00 PM

Answers

  • The secret to achieving the goal for which you are aiming is not to avoid erasing the parent, but to get the parent to redraw a subsection of itself just before you begin painting. The parent repaints itf, but only the section on which your control exists. Then you paint over that with a nice alpha blend.

    See this thread.


    Joel Ivory Johnson
    • Proposed as answer by Joel Ivory Johnson Thursday, August 6, 2009 9:12 PM
    • Marked as answer by ZHE ZHAO Thursday, August 13, 2009 1:55 AM
    Thursday, August 6, 2009 9:08 PM