Solved

VB.Net and RGBA color values

Posted on 2004-09-27
2
1,374 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

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

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

810 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