Solved

One Color left, one right and a mix between them?!

Posted on 2004-09-16
7
269 Views
Last Modified: 2010-04-23
Hello Together

I want to programm this:

I have one color at the left side, one at the right side und in the middle it should mix them...

Example: Left red, right Blue...

The more right you go the more blue it sould be...

How can I do this?

Thanks so much!

Sven
0
Comment
Question by:Dumdidum
  • 4
  • 2
7 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 40 total points
ID: 12075625
this will draw a lineargradient in a label (label1)
but the same applies for every control that as a graphics object

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim g As Graphics = Label1.CreateGraphics
        Dim mybrush As New System.Drawing.Drawing2D.LinearGradientBrush(New PointF(0, 0), New PointF(Label1.Width, Label1.Height), Color.Red, Color.Blue)
        g.FillRectangle(mybrush, g.ClipBounds)
end sub
0
 

Author Comment

by:Dumdidum
ID: 12075633
Thanks that's perfect!
0
 

Author Comment

by:Dumdidum
ID: 12076464
Hm, another problem:

It is working but if I put another window or anything else above it, the colors are disappearing...

Why?!

Sven
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12076591
than put the code in the paint event of the label

    Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
        Dim mybrush As New System.Drawing.Drawing2D.LinearGradientBrush(New PointF(0, 0), New PointF(Label1.Width, Label1.Height), Color.Red, Color.Blue)
        e.Graphics.FillRectangle(mybrush, e.Graphics.ClipBounds)
    End Sub
0
 

Author Comment

by:Dumdidum
ID: 12076758
Thanks - works great - but is it then possible to change the colors after starting the application?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12078057
Hi Dumdidum,

Here is a small app that demonstrates what you are asking:

Imports System.Drawing.Drawing2D

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ColorDialog1 As System.Windows.Forms.ColorDialog
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ColorDialog1 = New System.Windows.Forms.ColorDialog
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Panel1
        '
        Me.Panel1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Panel1.Location = New System.Drawing.Point(72, 8)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(256, 24)
        Me.Panel1.TabIndex = 0
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(8, 8)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(56, 24)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Color A"
        '
        'Button2
        '
        Me.Button2.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Button2.Location = New System.Drawing.Point(336, 8)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(56, 24)
        Me.Button2.TabIndex = 2
        Me.Button2.Text = "Color B"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(400, 38)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Panel1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private colorA As Color = Color.Red
    Private colorB As Color = Color.Blue

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ColorDialog1.ShowDialog = DialogResult.OK Then
            colorA = ColorDialog1.Color
            Panel1.Refresh()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If ColorDialog1.ShowDialog = DialogResult.OK Then
            colorB = ColorDialog1.Color
            Panel1.Refresh()
        End If
    End Sub

    Private Sub Panel1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.Resize
        Panel1.Refresh()
    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        Dim linGrBrush As New LinearGradientBrush(New Rectangle(0, 0, sender.width, sender.height), colorA, colorB, LinearGradientMode.Horizontal)
        e.Graphics.FillRectangle(linGrBrush, 0, 0, sender.width, sender.height)
        linGrBrush.Dispose()
    End Sub

End Class
0
 

Author Comment

by:Dumdidum
ID: 12078179
Thanks that's perfect!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Database Connections Not being returned to Connection Pool 7 27
ASP/VB email question 4 35
VB.net and sql server 4 36
Expression Evaluater 3 27
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question