Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1545
  • Last Modified:

VB.Net and RGBA color values

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
itcopt
Asked:
itcopt
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
itcoptAuthor Commented:
it worked thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now