Click here to Skip to main content
13,736,246 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I am new with Asp.net C#. Looking to create a Message Board where user can enter and make the message BOLD, Italic, and Underline. Also will be able to change the Forecolor For the text. Also the Font Name can be changed to according to what user picked from the Drop Down list.



Please help.

Thanks

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

namespace ProjectBoard
{
public partial class MessageBoardaspx : System.Web.UI.Page
{
private Style PrimaryStyle = new Style();

protected void Page_Load(object sender, EventArgs e)

{
if (!Page.IsPostBack)
{

// Adding Colors
ListItemCollection colors = new ListItemCollection();
colors.Add(System.Drawing.Color.Black.Name);
colors.Add(System.Drawing.Color.Blue.Name);
colors.Add(System.Drawing.Color.Green.Name);
colors.Add(System.Drawing.Color.Orange.Name);
colors.Add(System.Drawing.Color.Purple.Name);
colors.Add(System.Drawing.Color.Red.Name);
colors.Add(System.Drawing.Color.White.Name);
colors.Add(System.Drawing.Color.Yellow.Name);
Color.DataSource = colors;
Color.DataBind();

// Add FontName

ListItemCollection names = new ListItemCollection();
names.Add("Arial");
names.Add("Courier");
names.Add("Garamond");
names.Add("Times NEw Roman");
names.Add("Verdana");
FontNameList.DataSource = names;
FontNameList.DataBind();

// Add FontSize

ListItemCollection FontSizes = new ListItemCollection();
FontSizes.Add("Small");
FontSizes.Add("Medium");
FontSizes.Add("Large");
FontSizes.Add("10pt");
FontSizes.Add("14Pt");
FontSizes.Add("20pt");


}

}

protected void btnSubmit_Click(object sender, EventArgs e)
{
lblEnterMessage.Text = lblMessage.Text;

lblMessage.Text = txtMessage.Text;


string changestyles = "" + lblMessage.Text + "";


string url = string.Format("MessageDisplay.aspx?data={0}&color={1}", lblMessage.Text, Color.SelectedValue);

Response.Redirect(url);



}

protected void txtMessage_TextChanged(object sender, EventArgs e)
{

}


protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{


PrimaryStyle.ForeColor = System.Drawing.Color.FromName(Color.SelectedItem.Text);
lblMessage.ApplyStyle(PrimaryStyle);
txtMessage.ApplyStyle(PrimaryStyle);
lblMessage.ForeColor = System.Drawing.Color.FromName(Color.Text);
}

protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
PrimaryStyle.Font.Name = FontNameList.SelectedItem.Text;
lblMessage.ApplyStyle(PrimaryStyle);
txtMessage.ApplyStyle(PrimaryStyle);
}

protected void FontSizeList_SelectedIndexChanged(object sender, EventArgs e)
{
PrimaryStyle.Font.Size = FontUnit.Parse(FontSizeList.SelectedItem.Text);
lblMessage.ApplyStyle(PrimaryStyle);
txtMessage.ApplyStyle(PrimaryStyle);
}

protected void btntest_Click(object sender, EventArgs e)
{
lblMessage.Text = Color.SelectedValue;

}

protected void btnBold_Click(object sender, EventArgs e)
{



}


}
}
Posted 12-Dec-17 9:16am
Updated 13-Dec-17 4:53am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Assuming you want the user to be able to format their message, rather than changing the style of the entire page, use an HTML editor control.

For example:
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180920.1 | Last Updated 13 Dec 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100