Solved

VB.Net and RGBA color values

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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.
In this post we will learn different types of Android Layout and some basics of an Android App.
Progress
Starting up a Project

707 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