请问如何从一个拾色器中选中一个颜色之后能把这个值
返回给调用页且能使调用页立即做出变换成该所选颜色
的反应呢
如果有哪位可以提供比较好的拾色器代码和解决方法,
分不是问题

解决方案 »

  1.   

    在codeproject找来的例子,略做一下修改,自己改一下吧=========PickColor.aspx=========
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="PickColor.aspx.vb" Inherits="WebApplication1.WebForm1"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>Pick Color by Maui</title>
    <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
    <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:button id="Button1" style="Z-INDEX: 101; LEFT: 221px; POSITION: absolute; TOP: 40px" runat="server" Text="Make Palette" Width="114px" Height="25px"></asp:button><asp:dropdownlist id="DropDownList1" style="Z-INDEX: 102; LEFT: 134px; POSITION: absolute; TOP: 16px" runat="server" Width="73px" Height="19px"></asp:dropdownlist><asp:label id="Label1" style="Z-INDEX: 103; LEFT: 14px; POSITION: absolute; TOP: 13px" runat="server" Width="101px" Height="15px">Number of Row</asp:label><asp:label id="Label2" style="Z-INDEX: 104; LEFT: 17px; POSITION: absolute; TOP: 44px" runat="server" Width="39px" Height="13px"> Saturation</asp:label><asp:dropdownlist id="DropDownList2" style="Z-INDEX: 105; LEFT: 133px; POSITION: absolute; TOP: 45px" runat="server" Width="75px" Height="18px"></asp:dropdownlist>
    <TABLE id="Table1" style="Z-INDEX: 106; LEFT: 17px; POSITION: absolute; TOP: 102px; HEIGHT: 75px" borderColor="#000000" cellSpacing="1" cellPadding="1" width="700" border="3" runat="server">
    </TABLE>
    </form>
    </body>
    </HTML>
    =======PickColor.aspx.vb========
    Public Class WebForm1
        Inherits System.Web.UI.Page
        Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
        Protected WithEvents Label1 As System.Web.UI.WebControls.Label
        Protected WithEvents Label2 As System.Web.UI.WebControls.Label
        Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList
        Protected WithEvents Table1 As System.Web.UI.HtmlControls.HtmlTable
        Protected WithEvents Button1 As System.Web.UI.WebControls.Button#Region " Codice generato da Progettazione Web Form "    'Chiamata richiesta da Progettazione Web Form.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()    End Sub    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: questa chiamata al metodo ?richiesta da Progettazione Web Form.
            'Non modificarla nell'editor del codice.
            InitializeComponent()
        End Sub#End Region    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If IsPostBack = False Then
                Dim i
                For i = 10 To 150 Step 10
                    DropDownList1.Items.Add(Str(i))
                Next i
                For i = 100 To 0 Step -10
                    DropDownList2.Items.Add(Str(i) & "%")
                Next i
            End If
        End Sub    Private Sub Paletta(ByVal TargetForm As String, ByVal PalettaRow As Long, ByVal Saturation As Long)
            Dim RGBColor As String
            Dim Gray As Double
            Dim lum As Double
            Dim sat As Double
            Dim hue As Double
            Dim row As HtmlTableRow
            Dim cell As HtmlTableCell
            Dim RBGcolor As String        sat = Saturation / 100
            For hue = 0 To 359 Step (360 / PalettaRow)
                row = New HtmlTableRow()
                For lum = 0.1 To 1 Step 0.02
                    cell = New HtmlTableCell()
                    HlsToRgb(hue, lum, sat, RGBColor)
                    cell.BgColor = RGBColor
                    cell.Attributes.Add("onclick", "document.body.style.backgroundColor='" & RGBColor & "';")
                    cell.Attributes.Add("style", "cursor:hand;")
                    cell.Controls.Add(New HyperLink())
                    DirectCast(cell.Controls(0), HyperLink).Text = "_"
                    DirectCast(cell.Controls(0), HyperLink).ForeColor = Color.FromArgb(Val("&h" & Mid(RGBColor, 1, 2)), Val("&h" & Mid(RGBColor, 3, 2)), Val("&h" & Mid(RGBColor, 5, 2)))
                    'DirectCast(cell.Controls(0), HyperLink).NavigateUrl = TargetForm & "?&C=" & RGBColor
                    ' DirectCast(cell.Controls(0), HyperLink).NavigateUrl = "javascript:document.body.style.backgroundColor='" & RGBColor & "';return false;"
                    row.Cells.Add(cell)
                Next lum
                Table1.Rows.Add(row)
            Next hue
            row = New HtmlTableRow()
            For Gray = 0 To 255 Step 5.7
                cell = New HtmlTableCell()
                cell.BgColor = Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2)
                cell.Controls.Add(New HyperLink())
                DirectCast(cell.Controls(0), HyperLink).Text = "_"
                DirectCast(cell.Controls(0), HyperLink).ForeColor = Color.FromArgb(Gray, Gray, Gray)
                DirectCast(cell.Controls(0), HyperLink).NavigateUrl = TargetForm & "?&C=" & Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2)
                row.Cells.Add(cell)
            Next Gray
            Table1.Rows.Add(row)
        End Sub
        ' Converte HLS in RGB
        Private Sub HlsToRgb(ByVal H As Double, ByVal L As Double, ByVal S As Double, ByRef RGBColor As String)
            Dim p1 As Double
            Dim p2 As Double
            Dim r As Double
            Dim g As Double
            Dim b As Double        If L <= 0.5 Then
                p2 = L * (1 + S)
            Else
                p2 = L + S - L * S
            End If
            p1 = 2 * L - p2
            If S = 0 Then
                r = Int(L * 255)
                g = Int(L * 255)
                b = Int(L * 255)
            Else
                r = Int(QqhToRgb(p1, p2, H + 120) * 255)
                g = Int(QqhToRgb(p1, p2, H) * 255)
                b = Int(QqhToRgb(p1, p2, H - 120) * 255)
            End If
            RGBColor = Right("00" & Hex(r), 2) & Right("00" & Hex(g), 2) & Right("00" & Hex(b), 2)
        End Sub    Private Function QqhToRgb(ByVal q1 As Double, ByVal q2 As _
            Double, ByVal hue As Double) As Double
            If hue > 360 Then
                hue = hue - 360
            ElseIf hue < 0 Then
                hue = hue + 360
            End If
            If hue < 60 Then
                QqhToRgb = q1 + (q2 - q1) * hue / 60
            ElseIf hue < 180 Then
                QqhToRgb = q2
            ElseIf hue < 240 Then
                QqhToRgb = q1 + (q2 - q1) * (240 - hue) / 60
            Else
                QqhToRgb = q1
            End If
        End Function    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Paletta("Result.aspx", Val(DropDownList1.SelectedItem.Text), Val(DropDownList2.SelectedItem.Text))
        End Sub
    End Class
      

  2.   

    请问有C#的吗,我现在用的是ASP.NET+C#,谢谢!
      

  3.   

    实际上主要还是调用,然后赋值给textbox文本框中就可以了http://community.csdn.net/Expert/topic/3110/3110727.xml?temp=1.522243E-03
      

  4.   

    调用系统的颜色选择,注意 IE 5.5或者更高版本才能使用。。<HTML>
    <HEAD>系统颜色颜色<HEAD>
    <script>
    var sInitColor = null;
    function callColorDlg()  //打开系统颜色对话框,,,(只有IE6才支持)
    {
    if (sInitColor == null) 
    var sColor = dlgHelper.ChooseColorDlg();
    else
    var sColor = dlgHelper.ChooseColorDlg(sInitColor);

    sColor = sColor.toString(16);//把数字转换为16进制

    if (sColor.length < 6) 
    {
      var sTempString = "000000".substring(0,6-sColor.length);
      sColor = sTempString.concat(sColor); //如小于六位补足6位
    }

    oDiv.style.color= sColor;
    sInitColor = sColor;

    }
    document.body.onload=callColorDlg;
    </script>
    <body>
    <!-- 创建dlgHelper对象 -->
    <OBJECT id=dlgHelper CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px" ></OBJECT>
    </body>
    </html>
      

  5.   

    可以怎么能实时赋值使调用页面的LABLE能立即换成所选颜色呢,这个事件怎么驱动?
      

  6.   

    选择后,改动style模版的属性