Using style : Style « ASP.net Controls « ASP.NET Tutorial

ASP.NET Tutorial
1. ASP.Net Instroduction
2. Language Basics
3. ASP.net Controls
4. HTML Controls
5. Page Lifecycle
6. Response
7. Collections
8. Validation
9. Development
10. File Directory
11. Sessions
12. Cookie
13. Cache
14. Custom Controls
15. Profile
16. Configuration
17. LINQ
18. ADO.net Database
19. Data Binding
20. Ajax
21. Authentication Authorization
22. I18N
23. Mobile
24. WebPart
25. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.NET Tutorial » ASP.net Controls » Style 
3. 34. 8. Using style
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="UsingStyle" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
<table cellPadding="6" border="0">
                <tr>
                    <td>
                        <asp:label id="Label1" 
                            Text="Border Properties Example" Runat="server">
                            <center><br>Label Styles</center>
                        </asp:label>
                    </td>
                    <td>
                        <asp:button id="Button1" runat="server" 
                            Text="Button Styles">
                        </asp:button>
                    </td>
                    <td>
                        <asp:listbox id="ListBox1" Runat="server">
                            <asp:ListItem Value="0" Text="List Item 0">
                            </asp:ListItem>
                            <asp:ListItem Value="1" Text="List Item 1">
                            </asp:ListItem>
                            <asp:ListItem Value="2" Text="List Item 2">
                            </asp:ListItem>
                        </asp:listbox>
                    </td>
                    <td>
                        <asp:textbox id="TextBox1" 
                            Text="TextBox Styles" Runat="server">
                        </asp:textbox>
                    </td>
                    <td>
                        <asp:table id="Table1" Runat="server">
                            <asp:TableRow>
                                <asp:TableCell Text="(0,0)"></asp:TableCell>
                                <asp:TableCell Text="(0,1)"></asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell Text="(1,0)"></asp:TableCell>
                                <asp:TableCell Text="(1,1)"></asp:TableCell>
                            </asp:TableRow>
                        </asp:table>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label2" Runat="server" Text="Border Color:">
                        </asp:Label>
                        <asp:dropdownlist id="borderColorList" 
                            Runat="server" AutoPostBack="True" 
                            OnSelectedIndexChanged="ChangeBorderColor">
                        </asp:dropdownlist>
                        <br>
                        <asp:Label ID="Label3" Runat="server" Text="Border Style:">
                        </asp:Label>
                        <asp:dropdownlist id="borderStyleList" 
                            Runat="server" AutoPostBack="True"
                            OnSelectedIndexChanged="ChangeBorderStyle">
                        </asp:dropdownlist>
                        <br>
                        <asp:Label ID="Label4" Runat="server" Text="Border Width">
                        </asp:Label>
                        <asp:dropdownlist id="borderWidthList" 
                            Runat="server" AutoPostBack="True"
                            OnSelectedIndexChanged="ChangeBorderWidth">
                        </asp:dropdownlist>
                    </td>
                    <td>
                        <asp:Label ID="Label5" Runat="server" Text="Back Color:">
                        </asp:Label>
                        <asp:dropdownlist id="backColorList" 
                            Runat="server" AutoPostBack="True"
                            OnSelectedIndexChanged="ChangeBackColor">
                        </asp:dropdownlist>
                        <br>
                        <asp:Label ID="Label6" Runat="server" Text="Foreground Color:">
                        </asp:Label>
                        <asp:dropdownlist id="foreColorList" 
                            Runat="server" AutoPostBack="True"
                            OnSelectedIndexChanged="ChangeForeColor">
                        </asp:dropdownlist>
                    </td>
                    <td>
                        <asp:Label ID="Label7" Runat="server" Text="Font Name:">
                        </asp:Label>
                        <asp:dropdownlist id="fontNameList" 
                            Runat="server" AutoPostBack="True"
                            OnSelectedIndexChanged="ChangeFont">
                        </asp:dropdownlist>
                        <br>
                        <asp:Label ID="Label8" Runat="server" Text="Font Size:">
                        </asp:Label>
                        <asp:dropdownlist id="fontSizeList" 
                            Runat="server" AutoPostBack="True" 
                            OnSelectedIndexChanged="ChangeFontSize">
                        </asp:dropdownlist>
                    </td>
                </tr>
            </table>

    </form>
</body>
</html>


File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Drawing;

public partial class UsingStyle : System.Web.UI.Page
{
   private Style primaryStyle = new Style();

   protected void Page_Load(object sender, System.EventArgs e)
   {
      if (!Page.IsPostBack)
      {
         ListItemCollection colors = new ListItemCollection();
         colors.Add(Color.Black.Name);
         colors.Add(Color.Blue.Name);
         colors.Add(Color.Green.Name);
         colors.Add(Color.Orange.Name);
         colors.Add(Color.Purple.Name);
         colors.Add(Color.Red.Name);
         colors.Add(Color.White.Name);
         colors.Add(Color.Yellow.Name);
         borderColorList.DataSource = colors;
         borderColorList.DataBind();
         backColorList.DataSource = colors;
         backColorList.DataBind();
         foreColorList.DataSource = colors;
         foreColorList.DataBind();

         ListItemCollection styles = new ListItemCollection();
         Type styleType = typeof(BorderStyle);
         foreach (string s in Enum.GetNames(styleType))
         {
            styles.Add(s);
         }
         borderStyleList.DataSource = styles;
         borderStyleList.DataBind();

         ListItemCollection widths = new ListItemCollection();
         for (int i = 0; i < 11; i++)
         {
            widths.Add(i.ToString() "px");
         }
         borderWidthList.DataSource = widths;
         borderWidthList.DataBind();

         ListItemCollection names = new ListItemCollection();
         names.Add("Arial");
         names.Add("Courier");
         names.Add("Garamond");
         names.Add("Time New Roman");
         names.Add("Verdana");
         fontNameList.DataSource = names;
         fontNameList.DataBind();

         ListItemCollection fontSizes = new ListItemCollection();
         fontSizes.Add("Small");
         fontSizes.Add("Medium");
         fontSizes.Add("Large");
         fontSizes.Add("10pt");
         fontSizes.Add("14pt");
         fontSizes.Add("20pt");
         fontSizeList.DataSource = fontSizes;
         fontSizeList.DataBind();

         Label1.ApplyStyle(primaryStyle);
         ListBox1.ApplyStyle(primaryStyle);
         Button1.ApplyStyle(primaryStyle);
         Table1.ApplyStyle(primaryStyle);
         TextBox1.ApplyStyle(primaryStyle);
      }
   }
   protected void ChangeBorderColor(object sender, System.EventArgs e)
   {
      primaryStyle.BorderColor = Color.FromName(borderColorList.SelectedItem.Text);
      Label1.ApplyStyle(primaryStyle);
      ListBox1.ApplyStyle(primaryStyle);
      Button1.ApplyStyle(primaryStyle);
      Table1.ApplyStyle(primaryStyle);
      TextBox1.ApplyStyle(primaryStyle);
   }

   protected void ChangeBackColor(object sender, System.EventArgs e)
   {
      primaryStyle.BackColor = Color.FromName(backColorList.SelectedItem.Text);
      Label1.ApplyStyle(primaryStyle);
      ListBox1.ApplyStyle(primaryStyle);
      Button1.ApplyStyle(primaryStyle);
      Table1.ApplyStyle(primaryStyle);
      TextBox1.ApplyStyle(primaryStyle);
   }

   protected void ChangeForeColor(object sender, System.EventArgs e)
   {
      primaryStyle.ForeColor = Color.FromName(foreColorList.SelectedItem.Text);
      Label1.ApplyStyle(primaryStyle);
      ListBox1.ApplyStyle(primaryStyle);
      Button1.ApplyStyle(primaryStyle);
      Table1.ApplyStyle(primaryStyle);
      TextBox1.ApplyStyle(primaryStyle);
   }

   protected void ChangeBorderStyle(object sender, System.EventArgs e)
   {
      primaryStyle.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle),borderStyleList.SelectedItem.Text);
      Label1.ApplyStyle(primaryStyle);
      ListBox1.ApplyStyle(primaryStyle);
      Button1.ApplyStyle(primaryStyle);
      Table1.ApplyStyle(primaryStyle);
      TextBox1.ApplyStyle(primaryStyle);
   }

   protected void ChangeBorderWidth(object sender, System.EventArgs e)
   {
      primaryStyle.BorderWidth = Unit.Parse(borderWidthList.SelectedItem.Text);
      Label1.ApplyStyle(primaryStyle);
      ListBox1.ApplyStyle(primaryStyle);
      Button1.ApplyStyle(primaryStyle);
      Table1.ApplyStyle(primaryStyle);
      TextBox1.ApplyStyle(primaryStyle);
   }

   protected void ChangeFont(object sender, System.EventArgs e)
   {
      primaryStyle.Font.Name =
          fontNameList.SelectedItem.Text;
      Label1.ApplyStyle(primaryStyle);
      ListBox1.ApplyStyle(primaryStyle);
      Button1.ApplyStyle(primaryStyle);
      Table1.ApplyStyle(primaryStyle);
      TextBox1.ApplyStyle(primaryStyle);
   }

   protected void ChangeFontSize(object sender, System.EventArgs e)
   {
      primaryStyle.Font.Size =
          FontUnit.Parse(fontSizeList.SelectedItem.Text);
      Label1.ApplyStyle(primaryStyle);
      ListBox1.ApplyStyle(primaryStyle);
      Button1.ApplyStyle(primaryStyle);
      Table1.ApplyStyle(primaryStyle);
      TextBox1.ApplyStyle(primaryStyle);
   }

}
3. 34. Style
3. 34. 1. Test the border properties
3. 34. 2. set background color programmatically
3. 34. 3. This is a test of the color properties
3. 34. 4. Bold font
3. 34. 5. Working with the Font properties: Font-Italic, Font-Names,Font-Size
3. 34. 6. Set style attributes
3. 34. 7. Css style
3. 34. 8. Using style
3. 34. 9. Style asp.net server control
3. 34. 10. Font change
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.