Hi
I need to change the glyph image of the ribbons application button approximately once every seond.
I use the following code to draw a 24x24 PNG image to the glyph, from a TcxImageList:
ribbon.applicationButton.glyph.canvas.brush.color := clNone;
ribbon.applicationButton.glyph.canvas.FillRect( rect(0, 0, 24, 24) );
ilPNG.Draw(ribbon.applicationButton.glyph.canvas, 0, 0, random(il24x24.count), dsNormal, itImage);
The problem is that the glyph flickers, due to the .FillRect call, which is needed to clear the previously drawn glyph.
I've tried to put 'canvas.lock' / 'canvas.unlock' around the above code, but it still flickers.
Anyone know how that can be solved?
Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Hi Simon,
Thank you for the sample code, and please accept our apologies for the delay in responding.
However, from your post I don't quite understand the necessity to paint an image directly on the Glyph's Canvas. Perhaps, it is better to paint the required image on a temporary bitmap, and then assign it to the ApplicationButton.Glyph. Here is some sample code:
procedure TForm1.BitBtn1Click(Sender: TObject); var ABitmap: TBitmap; begin Inc(FIndex); if FIndex >= ImageList1.Count then FIndex := 0; ABitmap := TBitmap.Create; try ImageList1.GetBitmap(FIndex, ABitmap); dxRibbon1.ApplicationButton.Glyph.Assign(ABitmap); finally FreeAndNil(ABitmap); end; end;
Please try this solution, and let us know how it works for you.
Thanks,
Vito
Hi Vito,
Thanks for the response.
The problem with the sample code you provided, is that it results in a non-transparent application button glyph.
There's a white 24x24 squared area behind the assigned glyph image, even when the bitmap is extracted from a tcxImageList containing alpha transparent PNG images.
When drawing directly to the application button glyph, using the tcxImageList.draw method, it works great. With alpha transparency and all. But then I get the problem with flickering, because I have to clear the glyph area before redrawing it.
Hi Simon,
When working with the TcxImageList, please use its GetImage method to retrieve a transparent image. Attached is a small sample project, illustrating this approach. Please try it, and let us know your results.
Thanks,
Vito
Vito,
I just tried the sample project and it *almost* works.
But there is a problem when assigning alpha transparent images to the application button glyph. The alpha transparent part of the resulting glyph is drawn in black.
If you can't reproduce the issue with the sample project at your computer, pls let me know and I'll send a screenshot.
Hi Simon,
Thank you for the response.
I see the problem you described, and it looks as if the solution you initially found is the best way to accomplish this task. To prevent the application button from being clicked when clearing an image, please surround your code with the DxRibbon's BeginUpdate/EndUpdate methods. The code below illustrates this approach:
procedure TForm4.Timer1Timer(Sender: TObject); begin Inc(FIndex); if FIndex >= cxImageList1.Count then FIndex := 0; dxRibbon1.BeginUpdate; try dxRibbon1.applicationButton.glyph.canvas.brush.color := clNone; dxRibbon1.applicationButton.glyph.canvas.FillRect( rect(0, 0, 24, 24) ); cxImageList1.Draw(dxRibbon1.ApplicationButton.Glyph.Canvas, 0, 0, FIndex, dsNormal, itImage); finally dxRibbon1.EndUpdate; end; end;
Please let us know if this helps.
Thanks,
Vito
Thanks for the response.
> surround your code with the DxRibbon's
> BeginUpdate/EndUpdate methods
Even when surrounded with beginupdate / endupdate, it flickers.
Hi Simon,
Thank you for the response.
However, surrounding this code with BeginUpdate/EndUpdate method calls seems to fix the problem at our side. Attached is a small sample project that seems to work fine at our end. Please try it, and let us know how it goes.
Thanks,
Vito
Hi Vito,
Yep, the attached project works without flickering, but it uses the "assign" method to set the glyph, which causes the alpha transparent part of the glyph to be drawn incorrectly. (see earlier post in thread)
Hi Simon,
It appears that I attached an old project version to my previous post. Please accept my apologies for this mistake.
Attached is the correct version of this sample project. Please try it, and let us know your results.
Thanks,
Vito