Use System fonts and color items in the list

Source: Internet
Author: User

Sometimes we need to modify the font, color, size, and other items of our controls. At the same time, I also want to load the system's font list and color list in listeitem.

First create our file

Default2.aspx

 

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default2.aspx. cs" inherits = "default2" %>

<! 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">
<Div>
Select the background color <br/>
<Asp: dropdownlist id = "listbackcolor" runat = "server" width = "168px">
</ASP: dropdownlist> <br/>
<Br/>
Select font <br/>
<Asp: dropdownlist id = "lstfontname" runat = "server" width = "168px">
</ASP: dropdownlist> <br/>
<Br/>
Font size <br/>
<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox> <br/>
<Br/>
Border style <br/>
<Asp: radiobuttonlist id = "radiobuttonlist1" runat = "server">
</ASP: radiobuttonlist> </div>
<Br/>
<Br/>
<Asp: checkbox id = "chkpic" runat = "server" text = "use default image"/> <br/>
<Br/>
What to say <br/>
<Asp: textbox id = "textbox2" runat = "server" Height = "101px" textmode = "multiline" width = "192px"> </ASP: textbox> <br/>
<Br/>
<Asp: button id = "cmdupdate" runat = "server" text = "selected" onclick = "cmdupdate_click"/> <br/>
<Br/>
<Br/>
<Asp: Panel id = "pnlcard" runat = "server" Height = "70px" width = "476px">
<Br/>
<Asp: Label id = "lblgreeting" runat = "server" text = "label"> </ASP: Label> <br/>
<Br/>
<Asp: Image id = "imgdefault" runat = "server"/> </ASP: Panel>
<Br/>
<Br/>
</Form>
</Body>
</Html>

Default2.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;

Public partial class default2: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{

}
Protected void cmdupdate_click (Object sender, eventargs E)
{

}
}

Conventional cooking is to add content one by one in listitem. Then, in cmdupdate_click

Use

// Update the color

Pnlcard. backcolor = color. fromname (lstbackcolor. selecteditem. Text );

// Update the font

Lblgreeting. Font. Name = lstfontname. selecteditem. text;

// Set the font size

Lblgreeting. Font. size = fontunit. Point (int32.parse (textfontsize. Text ));

// Update the Border Width

Int bodervalue = int32.parse (lstborder. selecteditem. Value ):

Pnlcard. borderstyle = (borderstyle) bordervalue;

Another more systematic update Method

1. Obtain the list of all fonts installed.

System. Drawing. Text. installedfontcollection fonts;

Fonts = new system. Drawing. Text. installedfontcollection ();

Foreach (fontfamily family in fonts. Families)

{

Lstfontname. Items. Add (family. Name );

}

2. Get all installed colors

String [] colorarray = enum. getnames (typeof (system. Drawing. knowncolor ));

Lstbackcolor. datasource = colorarray;

Lstbackcolor. databind ();

3. The same is true for borderstyle.

String [] borderstylearray = enum. getnames (typeof (borderstyle ));

Lstborder. datasource = borderstylearray;

Lstborder. databind ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.