ASP Net Controls ASP.Net Tutorial

File: Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="MultiViewGreetingCardMaker" %>



    Untitled Page


    
    

            
                
                                                       runat="server" 
                                   ActiveViewIndex="0">
                                                          runat="server">
                                  Choose a foreground (text) color:
                                                                          runat="server" 
                                              AutoPostBack="True" 
                                              Height="22px"
                                              OnSelectedIndexChanged="ControlChanged" 
                                              Width="194px">
                            
                            
                            Choose a background color:
                                                            OnSelectedIndexChanged="ControlChanged" Width="194px">
                            
                            
                            
                            
                            " CommandName="NextView" />
                            
                            
                            
                        
                            Choose a border style:
                                                            Height="59px" OnSelectedIndexChanged="ControlChanged" RepeatColumns="2" Width="177px">
                            
                            
                                                            Text="Add the Default Picture"  />
                                
                            
                            
                            " CommandName="NextView" />
                            
                                
                        
                            Choose a font name:
                                                            OnSelectedIndexChanged="ControlChanged" Width="194px">
                            
                            
                            Specify a font size:
                            
                            
                            Enter the greeting text below:
                                                            TextMode="MultiLine" Width="240px" AutoPostBack="True">
                            
                            
                            
                            
                            
                        
                    
                
                
                                            " Width="339px">
                        
                         
                        
                        
                    
                
            
        

        
    


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;
using System.ComponentModel;
public partial class MultiViewGreetingCardMaker : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string[] colorArray = Enum.GetNames(typeof(System.Drawing.KnownColor));
            lstBackColor.DataSource = colorArray;
            lstBackColor.DataBind();
            lstForeColor.DataSource = colorArray;
            lstForeColor.DataBind();
            lstForeColor.SelectedIndex = 34;
            lstBackColor.SelectedIndex = 163;
            System.Drawing.Text.InstalledFontCollection fonts;
            fonts = new System.Drawing.Text.InstalledFontCollection();
            foreach (FontFamily family in fonts.Families)
            {
                lstFontName.Items.Add(family.Name);
            }
            string[] borderStyleArray = Enum.GetNames(typeof(BorderStyle));
            lstBorder.DataSource = borderStyleArray;
            lstBorder.DataBind();
            lstBorder.SelectedIndex = 0;
            imgDefault.ImageUrl = "http://www.rntsoft.com/style/logo.png";
        }
    }
    protected void ControlChanged(Object sender, EventArgs e)
    {
        pnlCard.BackColor = Color.FromName(lstBackColor.SelectedItem.Text);
        lblGreeting.ForeColor = Color.FromName(lstForeColor.SelectedItem.Text);
        lblGreeting.Font.Name = lstFontName.SelectedItem.Text;
        try
        {
            if (Int32.Parse(txtFontSize.Text) > 0)
            {
                lblGreeting.Font.Size = FontUnit.Point(Int32.Parse(txtFontSize.Text));
            }
            if (Int32.Parse(txtFontSize.Text) > 0)
            {
                lblGreeting.Font.Size =
                    FontUnit.Point(Int32.Parse(txtFontSize.Text));
            }
        }catch{
        }
        TypeConverter cnvrt = TypeDescriptor.GetConverter(typeof(BorderStyle));
        pnlCard.BorderStyle = (BorderStyle)cnvrt.ConvertFromString(lstBorder.SelectedItem.Text);
        if (chkPicture.Checked == true)
        {
            imgDefault.Visible = true;
        }
        else
        {
            imgDefault.Visible = false;
        }
        lblGreeting.Text = txtGreeting.Text;
    }
}