StrataFrame Forum

"Gradient Form Header" question

http://forum.strataframe.net/Topic10294.aspx

By Ben Hayat - 7/15/2007

I see this control uses Label and PictureBox to show "Title" and Image. The Title and Image show as transparent on Gradient background.



I also need to put label and Picture box on this control, but if they take the "BackColor" of the form and not the Gradient color of the control. How can I do it like the way Title and image shows?



Thanks!
By Ben Hayat - 7/15/2007

Never mind! Figured it out Smile



You can do really cool things with Gradation...
By Ben Hayat - 7/15/2007

I think I spoke too soon. I tried to use ThemedPanel, but causes me other issues.

For one, the base color throws everything off, even with opacity set 100.



I still would like to use the gradient header, but need to find out how to make label and picture transparent.

Thanks!
By Trent L. Taylor - 7/16/2007

I see this control uses Label and PictureBox to show "Title" and Image. The Title and Image show as transparent on Gradient background.

Actually it does not use an image or label.  These are rendered onto the control in the OnPaint of the control.

I still would like to use the gradient header, but need to find out how to make label and picture transparent.

Whenever you set a label or any other controls background to "Transparent" it will take the are on which is resides in its parent as the background....however, the GradientFormHeader control is not a parent control which means that no child object actually resides within the control itself.  So the labels parent is the form or container it resides within.

You have a couple of options.  First, just render your text on the gradient form header.  Handle the Paint event of the GradientFormHeader and just add your logic to render on top of it.  Second option would be to handle the Paint event of the label and capture the background of the rendered GradientFormHeader using the DrawToBitmap or the ScreenCapture classes...either way will work.  And then create your own transparency....this is ultimately what happens natively anyway.

The example above may be the approach you want to take.  I just created a new class, inherited from GradientFormHeader, overwrote the OnPaint method and added my logic.  You could create property that you set that adds this text to your header.  Below is the OnPaint code for the above example:

Public Class CustomHeader
    Inherits MicroFour.StrataFrame.UI.Windows.Forms.GradientFormHeader
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)
        e.Graphics.DrawString("My Custom Text", Me.Font, Drawing.Brushes.Red, 200, 10)
    End Sub
End Class
By Trent L. Taylor - 7/16/2007

Oh, your other question:

For one, the base color throws everything off, even with opacity set 100.

The valid values are 0-255, and this is the opacity for the gradient colors to show thorugh to the base color....not the transparency of the control itself.

By Ben Hayat - 7/16/2007

Good morning Trent; Thanks for detailed answer.



I understood your points very clearly, but due to the nature of my usage (I need to put lots of stuff on the form), it makes it hard to align everything via code rather using the designer. Here is a layout for my form using gradient background to start putting controls on them.



The valid values are 0-255, and this is the opacity for the gradient colors to show thorugh to the base color....not the transparency of the control itself.


The info on 255 solved my problem if I go with ThemedPanel.



Trent, if I don't have a way to host an image, is there a way to upload an image to the forum to show on the screen? I tried the "Insert Image", but it asks for URL, so I just attached it for you to look at my direction.



Thanks again!
By Ben Hayat - 7/16/2007

The valid values are 0-255, and this is the opacity for the gradient colors to show thorugh to the base color.




That's an interesting data. Can this be considered more like an 'alpha' channel? By combining the base into gradient, you can create new colors....Smile
By Trent L. Taylor - 7/16/2007

Can this be considered more like an 'alpha' channel?

That is what it is....the alpha.

By combining the base into gradient, you can create new colors

That was its purpose.  It allows the themed colors to be toned down/up based on your needs if you use the ColorsONly ThemeSupport option.

By Trent L. Taylor - 7/16/2007

I tried the "Insert Image", but it asks for URL, so I just attached it for you to look at my direction.

Use Internet Explorer to get a more detailed set of options to upload the image.  FireFox shows a different screen for some reason.

By Ben Hayat - 7/16/2007

It works in IE. Thanks Trent!