We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Caption Paint Event

Hello,

I want to be able to dynamically change the color(s) of the caption bar background and the caption image.

Usually I would hook into the Paint event but these do not seem to be exposed.

For example I want to be able to do something like:


private void FormCaptionPanel_Paint(object sender, PaintEventArg e)
{
var colorA = Color.White;
var colorB = Color.Black;
var gradientFillStyle = LinearGradientMode.Vertical;
var gradientBrush = new LinearGradientBrush(ClientRectangle, colorA, colorB, gradientFillStyle);
e.Graphics.FillRectangle(gradientBrush, ClientRectangle);
}

And call it somehow like this:
this.captionPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.FormCaptionPanel_Paint);

But the MetroForm doesn't seem to have these methods exposed. Is there anyway I can override these?

I am trying to do something similar for the Caption bar Image as well where I want to hook into the paint event but again this isn't exposed.

Thanks,


3 Replies

VR Vijayalakshmi Roopkumar Syncfusion Team June 23, 2017 07:17 AM UTC

Hi Jacob

Thank you for contacting Syncfusion Support.

We have prepared the sample that tries to meet your requirement. In order to change the Background of the CaptionBar and Caption Images of MetroForm dynamically, you can use the CaptionBarColor property of MetroForm and Backcolor property of CaptionImage class. Please find the code for the same from below:  
Code Example:[C#] 
   
// To Customize background color of CaptionBar dynamically   
this.CaptionBarColor = Color.Yellow;   
   
   
 
  
Code Example:[C#] 
   
foreach (CaptionImage image in this.CaptionImages)   
{   
// To Customize background color of CaptionImage dynamically   
image.BackColor = Color.Green ;   
}   
   
  
Screenshot: 
  
  
Screenshot shows the Backcolor applied for the CaptionImage after clicking the button: 
  
  
Screenshot shows the Backcolor applied for the CaptionBar after clicking the button. 
   
  

So we suggest you to use this property to change the desired color of CaptionBar and CaptionImage in MetroForm instead of hooking the paint event. Please check this sample and let us know if it helps you.

This above scenario is just an example. Kindly refer with Syncfusion Dashboard sample in below location for your further reference.

Sample Path: Syncfusion\EssentialStudio\[Installed Version]\Windows\Tools.Windows\Samples\Metro Style\Metro Style Controls \CS

Regards,
Vijayalakshmi V.R.  



JS JSpencer June 23, 2017 08:19 AM UTC

Hello,


Thanks for this.


I am aware of how to change the caption bar color like that.

The reasons why I wanted to hook into the paint event was to create a gradient effect on the caption bar, is this possible?



VR Vijayalakshmi Roopkumar Syncfusion Team June 27, 2017 04:49 AM UTC

Hi Jacob

We would like to inform you that MetroForm don’t have the reported support to expose the paint event currently. A support incident has been created under your account to track the status of this reported requirement. Please log on to our support website to check for further updates

https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents 

Please let me know if you have any questions.

Regards,
Vijayalakshmi V.R. 


Loader.
Up arrow icon