How to draw a gradient on a panel

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #35754
    Hamilton
    Participant

    Hi,

    I have a need to draw a gradient on a panel. The gradient needs to replicate the functionality from another application which means I need to implement StartColor, EndColor and Angle properties. I've seen that there are gradient functions in the sGradient unit but none of these seem to suit. I've also looked at the Jedi JclRegion.FillGradient function and whilst this does 'sort of' work it (a) doesn't allow me to specify an angle (only horizontal or vertical) and all the buttons are redrawn without the gradient when the mouseover occurs. I imagine I could override the Draw method to fix this but without the angle property I require it won't be a full solution anyway so I haven't pursued that.

    Can anyone suggest how I might put the gradient I require on a TsPanel?

    EDIT: I had to put square bracked to list because if you use round brackets then you end up with this smiley (:cool: in these forums!

    Regards,

    Hamilton

    #50569
    Support
    Keymaster

    Hello!

    Maybe you can use the GradientFill function from Windows API?

    http://msdn.microsof…v=vs.85%29.aspx

    Sample of using you can find in the sGradient.pas file.

    This function is very powerfull, I think.

    #50575
    CheshireCat
    Participant

    Hello,

    nice API-Call, but it cannot draw a gradient with different angles. Take a look to my attached demo, it shows an example how you can use GDI+ functions for drawing gradients. I hope this is what you've been looking for.

    [attachment=6334:gradient.jpg] [attachment=6335:DrawGradient.zip]

    #50576
    Support
    Keymaster

    I think, such gradient drawing is possible with this function, but maybe I'm wrong 🙂

    #50578
    Hamilton
    Participant

    Thank you both for the suggestions. Apologies that I ended up asking a non-AC question in these forums, I had thought there might be a library I had overlooked. Anyway I really appreciate you both taking the time to reply to an off-topic message as this turned out to be.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.