File: Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="MultiViewGreetingCardMaker" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<tr>
<td>
<asp:MultiView id="MultiView1"
runat="server"
ActiveViewIndex="0">
<asp:View ID="View1"
runat="server">
Choose a foreground (text) color:<br />
<asp:DropDownList ID="lstForeColor"
runat="server"
AutoPostBack="True"
Height="22px"
OnSelectedIndexChanged="ControlChanged"
Width="194px">
</asp:DropDownList><br />
<br />
Choose a background color:<br />
<asp:DropDownList ID="lstBackColor" runat="server" AutoPostBack="True" Height="22px"
OnSelectedIndexChanged="ControlChanged" Width="194px">
</asp:DropDownList>
<br />
<asp:Button ID="cmdNext" runat="server" Text="Next >" CommandName="NextView" />
</asp:View>
<asp:View ID="View2" runat="server">
Choose a border style:<br />
<asp:RadioButtonList ID="lstBorder" runat="server" AutoPostBack="True"
Height="59px" OnSelectedIndexChanged="ControlChanged" RepeatColumns="2" Width="177px">
</asp:RadioButtonList><br />
<br />
<asp:CheckBox ID="chkPicture" runat="server" AutoPostBack="True" OnCheckedChanged="ControlChanged"
Text="Add the Default Picture" />
<br />
<asp:Button ID="Button3" runat="server" Text="< Prev" CommandName="PrevView" />
<asp:Button ID="Button4" runat="server" Text="Next >" CommandName="NextView" />
</asp:View>
<asp:View ID="View3" runat="server">
Choose a font name:<br />
<asp:DropDownList ID="lstFontName" runat="server" AutoPostBack="True" Height="22px"
OnSelectedIndexChanged="ControlChanged" Width="194px">
</asp:DropDownList><br />
<br />
Specify a font size:<br />
<asp:TextBox ID="txtFontSize" runat="server" AutoPostBack="True" OnTextChanged="ControlChanged"></asp:TextBox><br />
<br />
Enter the greeting text below:<br />
<asp:TextBox ID="txtGreeting" runat="server" Height="85px" OnTextChanged="ControlChanged"
TextMode="MultiLine" Width="240px" AutoPostBack="True"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="< Prev" CommandName="PrevView" />
<asp:Button ID="Button2" runat="server" Text="Apply" />
</asp:View>
</asp:MultiView>
</td>
<td >
<asp:Panel ID="pnlCard" runat="server" Height="445px" HorizontalAlign="Center" Style="z-index: 101;
" Width="339px">
<br />
<asp:Label ID="lblGreeting" runat="server" Height="150px" Width="272px"></asp:Label>
<asp:Image ID="imgDefault" runat="server" Height="160px" Visible="False" Width="212px" />
</asp:Panel>
</td>
</tr>
</div>
</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;
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.java2java.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;
}
}
|