Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.Net Background gradient using LinearGradientBrush and display Image

I try to achieve to paint a form with a gradient backcolor and overlap an image with transparency.

This is possible?

I want using a tile background image with transparent background and paint the background with a custom linear gradient.

like image 312
MiBol Avatar asked Dec 16 '22 23:12

MiBol


1 Answers

I do it!, I want share my solution with you (It's pretty easy):

External help: Tile a Shape with an Image

Private Sub BackgroundGradient(ByRef Control As Object, _
                                ByVal Color1 As Drawing.Color, _
                                ByVal Color2 As Drawing.Color)

    Dim vLinearGradient As Drawing.Drawing2D.LinearGradientBrush = _
        New Drawing.Drawing2D.LinearGradientBrush(New Drawing.Point(Control.Width, Control.Height), _
                                                    New Drawing.Point(Control.Width, 0), _
                                                    Color1, _
                                                    Color2)

    Dim vGraphic As Drawing.Graphics = Control.CreateGraphics
    ' To tile the image background - Using the same image background of the image
    Dim vTexture As New Drawing.TextureBrush(Control.BackgroundImage)

    vGraphic.FillRectangle(vLinearGradient, Control.DisplayRectangle)
    vGraphic.FillRectangle(vTexture, Control.DisplayRectangle)

    vGraphic.Dispose() : vGraphic = Nothing : vTexture.Dispose() : vTexture = Nothing
End Sub
like image 84
MiBol Avatar answered May 20 '23 00:05

MiBol