Can't set transpparent control as doublce buffer

  • Thread starter °Ë´óɽÈË
  • Start date
°

°Ë´óɽÈË

HI,

I create a custom transparent control, set the style is
ControlStyles.DoubleBuffer, It display black background. How
to create a double buffer transparent control?

The ralative code is:
// in constructor
base.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.StandardClick |
ControlStyles.Opaque, true);
 
S

Stoitcho Goutsev \(100\) [C# MVP]

I think you have asked this before. You cannot use build-in double buffering
with transparent controls. You need to maintain you own bitmap and blend it
with the background. If you need really simple transparency (e.g
rounded-corner buttons) take a look at control's Region property
 
°

°Ë´óɽÈË

Hi,
Thank you for your response. I really have some big problems in Transparent
control.
Can you help me?

1. Can you give me some detail information about double buffer transparent
control? I found that In .net FrameWork, SelectionUIService is implemented
by a double buffer transparent control, It can work.

2. I must set the parent control as ~WS_CLIPCHILDREN, the transparent
control can work. Because If I don't do it, Parent control will not repaint
the area occurred by transparent. The back ground of transparent Control
will not correct. But I don't think it is a good ideal.

3. What's different between SupportTranparentBackColor and Opaque. If I set
control as SupportTranparentBackColor And set the BackColor, It's
transparent also. I know control will not paint back ground if I set it as
Opaque. They can implement Transparent control all. But I don't know who is
the really transparent control and what the different between them.


Can you give me any information about them? Thank you very much.

Jerry


Stoitcho Goutsev (100) said:
I think you have asked this before. You cannot use build-in double buffering
with transparent controls. You need to maintain you own bitmap and blend it
with the background. If you need really simple transparency (e.g
rounded-corner buttons) take a look at control's Region property

--
HTH
Stoitcho Goutsev (100) [C# MVP]


°Ë´óɽÈË said:
HI,

I create a custom transparent control, set the style is
ControlStyles.DoubleBuffer, It display black background. How
to create a double buffer transparent control?

The ralative code is:
// in constructor
base.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.StandardClick
|
ControlStyles.Opaque, true);
 
°

°Ë´óɽÈË

Hi,
Thank you for your response. I really have some big problems in Transparent
control.
Can you help me?

1. Can you give me some detail information about double buffer transparent
control? I found that In .net FrameWork, SelectionUIService is implemented
by a double buffer transparent control, It can work.

2. I must set the parent control as ~WS_CLIPCHILDREN, the transparent
control can work. Because If I don't do it, Parent control will not repaint
the area occurred by transparent. The back ground of transparent Control
will not correct. But I don't think it is a good ideal.

3. What's different between SupportTranparentBackColor and Opaque. If I set
control as SupportTranparentBackColor And set the BackColor, It's
transparent also. I know control will not paint back ground if I set it as
Opaque. They can implement Transparent control all. But I don't know who is
the really transparent control and what the different between them.


Can you give me any information about them? Thank you very much.

Jerry


Stoitcho Goutsev (100) said:
I think you have asked this before. You cannot use build-in double buffering
with transparent controls. You need to maintain you own bitmap and blend it
with the background. If you need really simple transparency (e.g
rounded-corner buttons) take a look at control's Region property

--
HTH
Stoitcho Goutsev (100) [C# MVP]


°Ë´óɽÈË said:
HI,

I create a custom transparent control, set the style is
ControlStyles.DoubleBuffer, It display black background. How
to create a double buffer transparent control?

The ralative code is:
// in constructor
base.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.StandardClick
|
ControlStyles.Opaque, true);
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Well...
2. I must set the parent control as ~WS_CLIPCHILDREN, the transparent
control can work. Because If I don't do it, Parent control will not repaint
the area occurred by transparent. The back ground of transparent Control
will not correct. But I don't think it is a good ideal.

If a window has style WS_CLIPCHILDREN it will clip off all the area
occupied by its child controls. Which means that it cannot draw on this
areas. Normaly this is what you want because you don't want to draw over
buttons, listboxes, etc. However if you have transparent child control you
should turn this style off becasue otherwise parent window cannot draw under
that control. All the drawing is clipped off and the effect is not what is
expected.
3. What's different between SupportTranparentBackColor and Opaque. If I set
control as SupportTranparentBackColor And set the BackColor, It's
transparent also. I know control will not paint back ground if I set it as
Opaque. They can implement Transparent control all. But I don't know who is
the really transparent control and what the different between them.

If you set SupportTranparentBackColor you can have translucent control.
Control paints the background, but it uses colors with alpha component less
then 255. When you use Opaque you either draw the background or not. You
cannot control the translucency.

When you use SupportTranparentBackColor it works with all the stuff drawn
one the parent control surface (Windows doesn't suport translucent colors
for control backgrounds so this is simulated by the framework, btw you can
use double buffering with that), but it do not take care of any sibling
controls. In other words control will cover all buttons, listboxes, etc,
which are underneath.

If you use Opaque you can do transparent control, but you need to remove
parent's WS_CLIPCHILDREN as well as the control should not cover any sibling
controls unless they don't have thier WS_CLIPSIBLINGS style removed. Anyways
you cannot use build-in double bufferning because nobody paints the
background and your bitmap will have black anywhere you haven't drawn.

The only solution would be to redesign your application and draw everything
in your own bitmap. Before the drawing fill the bitmap with color that you
going to use as a transparent color (key color).
When finish drawing in the bitmap. Transfer the bitmap on the screen
(frankly I haven't test it, but I believe you have to use parent's Graphics
object). Use Graphics.DrawImage that accepts ImageAttribute parameter and
set transparent color to be your key color.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top