Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gradient Backdrop in Visual Basic
11-19-2009, 04:51 AM (This post was last modified: 10-12-2010 05:38 AM by drdebcol.)
Post: #1
Gradient Backdrop in Visual Basic
Making gradient visibility of objects is fun. I did that in Delphi and now i will explain how to do it in Visual Basic. You have Delphi code here :
http://www.pro9ramming.com/gradient-form-t-175.html
I will do this by creating private sub, you have it here :
Code:
Private Sub DrawFormGradient( _
                 ByVal TopColor As Color, _
                 ByVal BottomColor As Color)
  Dim objBrush As New Drawing2D.LinearGradientBrush _
    (Me.DisplayRectangle, _
    TopColor, _
    BottomColor, _
    Drawing2D.LinearGradientMode.Vertical)
  Dim objGraphics As Graphics = _
            Me.CreateGraphics()
  objGraphics.FillRectangle(objBrush, _
            Me.DisplayRectangle)
  objBrush.Dispose()
  objGraphics.Dispose()
End Sub
And you will call this code using this :
Code:
Private Sub Form1_Paint(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.PaintEventArgs) _
        Handles MyBase.Paint
  DrawFormGradient(Color.Blue, Color.AliceBlue)
End Sub
Don't use two very different colors because that could make contra-effect an people. And you can edit this code to make it like a gradient from left to right, or horizontal.
Here is the example of using this on green and red color. First you call function like this :
Code:
Private Sub Form1_Paint(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.PaintEventArgs) _
        Handles MyBase.Paint
  DrawFormGradient(Color.Green, Color.Red)
End Sub
And you should get this as a result :

[Image: grad2.JPG]

There is one function which you can use and that is Color.FromArgb() which means Alpha,Red,Green,Blue. You have 4 in arguments :
Code:
Alpha (0..255) Amount of transparency
Red (0..255) Amount of red color
Green (0..255) Amount of green color
Blue (0..255) Amount of blue color
And if you mix all of them together you can get your color which you want and that is not standard VB color.
And you can call this function like this :
Code:
Dim NewColor As Color = Color.FromArgb(aplha, red, green, blue)
And certainly you can use this "NewColor" wherever you want !
Hope that you like this tut !

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
11-20-2009, 06:32 AM
Post: #2
RE: Gradiend Backdrop in Visual Basic
I never knew you coded in Visual Basic .net Tongue

Nice work, keep it up!

Find all posts by this user
Quote this message in a reply
11-20-2009, 06:33 AM
Post: #3
RE: Gradiend Backdrop in Visual Basic
I coded a bit in macros and i worked a bit in VB 6 2 years ago, but now i decided to get some of codes that i used and to explain them !

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
12-30-2009, 07:16 AM
Post: #4
RE: Gradient Backdrop in Visual Basic
Thats hot!

[Image: pgsig copy.png]
Visit this user's website Find all posts by this user
Quote this message in a reply
12-30-2009, 07:01 PM
Post: #5
RE: Gradient Backdrop in Visual Basic
(12-30-2009 07:16 AM)FreckleS Wrote:  Thats hot!
Who said it is not ?

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
03-12-2010, 08:51 PM
Post: #6
RE: Gradient Backdrop in Visual Basic
Nice One I like it!
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: