Introduction
In this
article I explain how to convert the HTML colors to the c# colors because in c#
we have only limited number of colors like example red, green, blue etc…. If
you want to display the color some shaded color and RGB color mixing process
you can use this methods to overcome this functionalists
Write the
below code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SampleTestingCodes
{
public partial class ColorClass :
System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
Label1.ForeColor = ColorTranslator.FromHtml("#FFFFF");
Label1.ForeColor = ColorTranslator.FromHtml("#E14900");
Label1.ForeColor = ColorTranslator.FromWin32(0xA000);
string Html = ColorTranslator.ToHtml(Color.Green);
int Ole = ColorTranslator.ToOle(Color.Blue);
int
Win32 = ColorTranslator.ToWin32(Color.Red);
ScriptManager.RegisterStartupScript(this, this.GetType(),
"script", "alert('"
+ Win32 + "');", true);
}
}
}
----------------------------------------------------------------------------------
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeBehind="ColorClass.aspx.cs"
Inherits="SampleTestingCodes.ColorClass"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
No comments:
Post a Comment