Solved

VB.Net and RGBA color values

Posted on 2004-09-27
2
1,326 Views
Last Modified: 2008-03-06
Hello,

I am new to VB.net and I am working on a project that shows the effect of various RGBA values on the color produced.
I have to define the RGBA value for each scroll bar for each value. four scroll bars red,green,blue and alpha. and display the output color to a filled rectangle each time the value changed event for the scroll bar is changed.

*************below is the paint event handler that brings up the rectangle on the first form load:

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint


        Dim graCurrent As Graphics = e.Graphics
        Dim recCurrent As Rectangle
        Dim colCurrent As Color
        Dim sbCurrent As SolidBrush, penCurrent As Pen
        recCurrent = New Rectangle(255, 48, 168, 232)
        sbCurrent = New SolidBrush(Color.Blue)
        graCurrent.FillRectangle(sbCurrent, recCurrent)

******Then under the scroll bar change, I have

Private Sub vscRed_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles vscRed.ValueChanged
Dim curRed As Integer
        Dim sbCurrent As SolidBrush
        Dim colCurrent As Color
        Dim recCurrent As Rectangle
        Dim graCurrent As Graphics

        sbCurrent = New SolidBrush(Color.FromArgb(vscAlpha.Value, vscRed.Value, vscGreen.Value, vscBlue.Value))
        lblValueRed.Text = vscRed.Value.ToString
        lblValueGreen.Text = vscGreen.Value.ToString
        lblValueBlue.Text = vscBlue.Value.ToString
        lblValueAlpha.Text = vscAlpha.Value.ToString
        recCurrent = New Rectangle(255, 48, 168, 232)
        sbCurrent = New SolidBrush(Color.Black)

*********I am not sure of the sytax to rebuild the rectangle to reflect the color change of the scroll bars. If I try the graCurrent.FillRectangle in the scroll event I get an error saying it needs to be in the Paint event handler.  Could this be a simple if statement in the paint event that could fire off the scroll value changed event?
Also the values of the scroll bar are not showing 255 full range
Please advise, Thanks Pam.

0
Comment
Question by:itcopt
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 12164024
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim graCurrent As Graphics = e.Graphics
        Dim recCurrent As Rectangle
        Dim colCurrent As Color
        Dim sbCurrent As SolidBrush

        recCurrent = New Rectangle(255, 48, 168, 232)
        sbCurrent = New SolidBrush(Color.FromArgb(vscAlpha.Value, vscRed.Value, vscGreen.Value, vscBlue.Value))
        graCurrent.FillRectangle(sbCurrent, recCurrent)
        lblValueRed.Text = vscRed.Value.ToString
        lblValueGreen.Text = vscGreen.Value.ToString
        lblValueBlue.Text = vscBlue.Value.ToString
        lblValueAlpha.Text = vscAlpha.Value.ToString
        sbCurrent.Dispose()
End Sub

Private Sub vscRed_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles vscRed.ValueChanged, vscGreen.ValueChanged, vscBlue.ValueChanged, vscAlpha.ValueChanged
    Me.Refresh()
End Sub
0
 

Author Comment

by:itcopt
ID: 12212917
it worked thanks!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
linearIn  challenge 23 65
scores100 challenge 3 83
scoresClump  challenge 31 108
silent install of security banner via msiexec command 4 50
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now