Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Color Gradient in VB for use in generating Color Chart

Status
Not open for further replies.

ASPNETnewbie

Programmer
May 9, 2006
93
US
I was wondering if anyone has an idea of how I can program a color-gradient value capturing function. My program will recieve 3 values as input ( StartColor and EndColor and NumberofGradientColors). The function will then return an array of NumberofGradient colors that exist between the two inputted colors. Can anyone help please?


AspNetNewbie
 
Was wondering if you can help me. What I have now is the code below which basically starts me with what I need but I would like to have something from someone who has maybe worked on this before. Right now I need help with dealing with the chart generator which happens to be a flash file. I want to in a user control embed this same swf program so that on load, user selects the STARTCOLOR and ENDCOLOR and number of bars to create and maybe the width and Height of the Chart itself, push the Submit Button and have the User Control Display the Chart generated.

This is the code for the ChartGenerator
===========================================================

<object id="FC_2_3_Column3D" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="flash/swflash.cab#version=6,0,0,0" height="350" width="700">
<param name="movie" value="../Charts/FC_2_3_Column3D.swf">
<param name="FlashVars" value="&dataURL=Data.xml&chartWidth=700&chartHeight=350">
<param name="quality" value="high">
<param name="bgcolor" value="#FFFFFF">
<embed bgcolor="#FFFFFF" flashvars="&dataURL=Data.xml&chartWidth=700&chartHeight=350"
height="350" name="FC_2_3_Column3D" pluginspage=" quality="high" src="../Charts/FC_2_3_Column3D.swf" type="application/x-shockwave-flash"
width="700"></embed>
</object>
===========================================================

Situation I have now is since I also need to make the width and Height features changable by user, and I want to wrap the Chart object in a UserControl, how can do I do and still have it work even after I have made the changes.


ASPNETNEWBIE



BELOW is my GRADIENT GENERATOR
===========================================================

Imports System
Imports System.Drawing

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then

End If
End Sub

Public Function GetGradients(ByVal StartColor As Drawing.Color, ByVal EndColor As Drawing.Color, ByVal NumGradients As Integer) As String()
Dim clrRet(NumGradients - 1) As String
Dim i As Integer
Dim iR As Integer = 0
Dim iG As Integer = 0
Dim iB As Integer = 0

Dim rSecSize = (Convert.ToInt32(StartColor.R) - Convert.ToInt32(EndColor.R)) / NumGradients
Dim gSecSize = (Convert.ToInt32(StartColor.G) - Convert.ToInt32(EndColor.G)) / NumGradients
Dim bSecSize = (Convert.ToInt32(StartColor.B) - Convert.ToInt32(EndColor.B)) / NumGradients

For i = 0 To NumGradients - 2

iR = Convert.ToInt32(StartColor.R) + ((rSecSize * -1) * i)
iG = Convert.ToInt32(StartColor.G) + ((gSecSize * -1) * i)
iB = Convert.ToInt32(StartColor.B) + ((bSecSize * -1) * i)

clrRet(i) = RGBToHex(iR, iG, iB)
Next
clrRet(NumGradients - 1) = RGBToHex(Convert.ToInt32(EndColor.R), Convert.ToInt32(EndColor.G), Convert.ToInt32(EndColor.B))
Return clrRet
End Function

Public Function RGBToHex(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As String
Return String.Format("{0:X2}{1:X2}{2:X2}", R, G, B)
End Function

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim start As Color = System.Drawing.ColorTranslator.FromHtml(TextBox1.Text)
Dim ends As Color = System.Drawing.ColorTranslator.FromHtml(TextBox2.Text)
Dim numb As Integer = Int32.Parse(TextBox3.Text)

ListBox1.DataSource = GetGradients(start, ends, numb)
ListBox1.DataBind()
End Sub
End Class
 
You might want to pop over to forum796 for VB.NET questions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top