[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-09-16
7
Medium Priority
?
277 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 160 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 86

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month17 days, 17 hours left to enroll

830 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