Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change color depth on form

Status
Not open for further replies.

EZEason

Programmer
Joined
Dec 11, 2000
Messages
213
Location
US
I would like to change the color depth of a form from white at the top to a light blue at the buttom. Anyone have any suggestions or examples?

What doesn't kill you makes you stronger.
 
Sure:
Play aroung with with code...


Code:
    Private Sub Form1_Resize(ByVal sender As Object, _
                ByVal e As System.EventArgs) Handles MyBase.Resize

        MakeGradient()
    End Sub

    Private Sub Form1_Activated(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles MyBase.Activated

        MakeGradient()
    End Sub

    Private Sub MakeGradient()
        Dim objBrush As New Drawing2D.LinearGradientBrush _
            (Me.DisplayRectangle, _
            Color.Blue, _
            Color.AliceBlue, _
            Drawing2D.LinearGradientMode.Vertical)

        Dim objGraphics As Graphics = Me.CreateGraphics()

        objGraphics.FillRectangle(objBrush, Me.DisplayRectangle)

        objBrush.Dispose()
        objGraphics.Dispose()
    End Sub



-bclt
 
yep. in the onpaint event of the form draw a rectagle on the graphics of the form.

Code:
    Dim gr As Graphics = Me.CreateGraphics
    Dim rect As New Rectangle(0, 0, 10, 10)
    Private xStartColor As Color = Color.LightSteelBlue
    Private xEndColor As Color = Color.SteelBlue
    Private xLinearGradientMode As LinearGradientMode = LinearGradientMode.Vertical
    Dim br As New LinearGradientBrush(rect, xStartColor, xEndColor, xlineargradientmode)

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        UpdateGraphics()
    End Sub

    Private Sub UpdateGraphics()
        gr = Me.CreateGraphics
        gr.Clear(Me.BackColor)

        If Me.Width > 0 And Me.Height > 0 Then
            rect = New Rectangle(0, 0, Me.Size.Width, Me.Height)
            br = New LinearGradientBrush(rect, xStartColor, xEndColor, xLinearGradientMode)
            gr.FillRectangle(br, rect)

        End If
    End Sub

    Private Sub UserControl1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        UpdateGraphics()
    End Sub

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
OK, I'm using the VB.net Power Pack. It works fine. But now I'm having a problem with a dynamic control (MSChart) that is add during runtime. I can not see the control once it is added. I think my problem is that I'm adding the control the the form and not the blendpanel. The procedure that adds the control is in a moduel. So I can not see the blendpanel from the moduel. Like:
Code:
me.BlendPanel1.add
How do I add a control to a Blend Panel from a moduel???

What doesn't kill you makes you stronger.
 
I got it.
I just needed to add the form the the module.
Code:
Public Form1 as New Form1

What doesn't kill you makes you stronger.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top