?
Solved

VB.Net and RGBA color values

Posted on 2004-09-27
2
Medium Priority
?
1,477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
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 …
Progress
Suggested Courses

801 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