IMBack

HI ..

I have some text in a textbox. and I want to allow a user to select some text and convert it to BOLD by clicking a button.

Is there away to capture what user selected once the user clicked a button.

Thank you,



Re: Windows Forms General capture text from textbox

Ðãv? S. Â???????

For starters, if you would like your user to select "part" of the text and make that bold, you will have to use the RichTextBox control. The TextBox control does not support advanced string formatting like that. Assuming that is what you want, you can use the following code in your button's ClickEvent.

if (this.richTextBox1.SelectionFont.Bold)
{
richTextBox1.SelectionFont = new Font(
this.richTextBox1.Font.FontFamily,
this.richTextBox1.Font.Size,
FontStyle.Regular);
}
else
{
richTextBox1.SelectionFont = new Font(
this.richTextBox1.Font.FontFamily,
this.richTextBox1.Font.Size,
FontStyle.Bold);
}





Re: Windows Forms General capture text from textbox

JeroGrav

To get the selected text in a textbox, you need to use a combination of the SelectionStart and SelectionLength properties.

But I don't think a textbox is going to work for you. TextBoxes don't allow the sort of formatting you are wanting to do. You can make the entire thing bold, but not part of it bold and the other part normal.

I think you will need to check out hte RichTextBox instead.

Regards






Re: Windows Forms General capture text from textbox

IMBack

Thank you for the reply.

I am doing this in a web application. and RichTextBox is a Windows.Form component.

So What I did I added a reference "System.Windows.Form" and wrote this code to display the component on the web

RichTextBox richTextbox = new RichTextBox();

this.Controls.Add(richTextbox);

but it gives me an error and does not compile it (2 line) . It says "Cannot convert from System.Windows.Forms.RichTextBox to System.Web.UI.Control...


Is there another way to display the component on the web..

Thank you.





Re: Windows Forms General capture text from textbox

Ðãv? S. Â???????

For ASP.NET questions you should be posting on the official ASP.NET forums. This forum is for Windows Forms development.

As for your question, this cannot be achieved using the standard System.Web.UI.WebControls.TextBox control. You will have to find some other solution.






Re: Windows Forms General capture text from textbox

JeroGrav

Sorry for the confusion.

I assumed that you were doing a WinForms application because this is the forum specifically for Winforms stuff. Thats why I suggest the RishTextBox.

You'll have to ignore the RichTextBox. Trying to use System.Windows.Forms in your web app is the wrong thing to do.

Try posting your question on one of the asp.net forums. you will get a better response there.

Regards






Re: Windows Forms General capture text from textbox

Ðãv? S. Â???????

No offense, but its kind of annoying reading you repeat what I say. : |





Re: Windows Forms General capture text from textbox

IMBack

Thank you all..

I will post the question on ASP.NET forums website.