Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I've a multimode textbox (textbox1) and dropdownlist controls.

Dropdownlist contains FontFamilies.

My question is: When I select some part of text in textbox, font should change as I select required font.

Please reply with an example.
Posted
Updated 6-Jun-11 21:20pm
v3
Comments
Dalek Dave 7-Jun-11 3:21am    
Edited for Grammar and Readability.
Sandesh M Patil 7-Jun-11 6:32am    
If you select the required font family in Dropdownlist, the focus will go on Dropdownlist and your selected text in textbox is not selected?

It is not possible bit have differential styling within a HTML <textarea>, which is what I think the multiline text box translates to. You will need to use some form of rich editor if you want that.
 
Share this answer
 
 
Share this answer
 
v2
Comments
ks ravi 7-Jun-11 1:56am    
thnks for the reply but i think you dont understand my query.My query is, only selected text to be change as i keep changing FontFamily or Size.
What is the exact requirement, just think on it, and if you have an option then go for a richtext editor.

Which will help you to make a good contol over the text other than only the font you can also make it bold, italic..... etc
 
Share this answer
 
Comments
ks ravi 7-Jun-11 1:56am    
thnks for the reply but i think you dont understand my query.My query is, only selected text to be change as i keep changing FontFamily or Size.
Hope this[^] might help you.
 
Share this answer
 
Comments
ks ravi 7-Jun-11 1:56am    
thnks for the reply but i think you dont understand my query.My query is, only selected text to be change as i keep changing FontFamily or Size.
Try This...
XML
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" ID="txt1" TextMode="MultiLine" />
<asp:HiddenField runat="server" ID="hidSelectedText" />
<asp:Button runat="server" ID="showselected" Text="Show selected" OnClientClick="doselection();" OnClick="showselected_Click" />
<script type="text/javascript">
function doselection()
{
if (window.getSelection)
{
txt = window.getSelection();
}
else if (document.getSelection)
{
txt = document.getSelection();
}
else if (document.selection)
{
txt = document.selection.createRange().text;
}
else
{
alert('selection not supported');
}
document.getElementById('<%=hidSelectedText.ClientID %>').value = txt;
}
</script>
</div>
</form>

C#
protected void showselected_Click(object sender, EventArgs e)
{

Response.Write(hidSelectedText.Value);

}
 
Share this answer
 
v3
Comments
Dalek Dave 7-Jun-11 3:23am    
Edited for Code Blocks.
for that you should have RichTextBox.........
public void CreateMyRichTextBox()
{
    RichTextBox richTextBox1 = new RichTextBox();
    richTextBox1.Dock = DockStyle.Fill;

    richTextBox1.LoadFile("C:\\MyDocument.rtf");
    richTextBox1.Find("Text", RichTextBoxFinds.MatchCase);
    richTextBox1.SelectionFont = new Font("Verdana", 12, FontStyle.Bold);
    richTextBox1.SelectionColor = Color.Red;
    richTextBox1.SaveFile("C:\\MyDocument.rtf", RichTextBoxStreamType.RichText);
    this.Controls.Add(richTextBox1);
}


Or see this link
 
Share this answer
 
Comments
parmar_punit 7-Jun-11 4:48am    
I hope it will useful to you....
if you fount this code useful, dont forget to accept this answer an vote it up.
Like BobJanovas says, you cannot have multiples font in a textbox. If you don't want to implement a rich editor, you can implement a "preview" panel like CodeProject does.

Here you got a good Rich Text Editor:
http://ckeditor.com/[^]

It's free. I used it. It's really good

If you need more help, please let me know.

Regards.
 
Share this answer
 
Use
Request.Form["idofTextbox"];
dont use idoftext.text here..it doesnt contain updated value..Hope it solves ur problem.. :)
 
Share this answer
 
Comments
[no name] 4-Sep-13 13:08pm    
The problem was solved 2 years ago. Do you think that he is still waiting after all this time?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900