How to Format Text in a TextBox control

Discussion in 'ASP.NET / ASP.NET Core' started by joelnet, Dec 24, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. \n is linefeed character for c# (though i'd recommend using \r\n)
    since you are using vb.net, you need to change your code to this...

    mytextbox.text = "this is a line of text" & vbCrLf & "This should be the next line of text"


    Joel Thoms

    DiscountASP.NET
    http://www.DiscountASP.NET
     
  2. steurm


    Thank youfor your responce a RichTextBox control sure seems like the answer but it also seems like over kill. In my application the user does not change the text. I will be the one assigning different formated strings to the textbox. All of the responces I have gotten from other forums makes me feel like I am not making my need clear. I'm sorry if this is the case. Let me try again.


    The User will select a radio button. I will assign the text to be displayed. I would like to be able to format the text ie: Color, Bold, size...... that I will put in the display area (Text Box). Again the myTextBox.text = "My string where this word is RED and this word is BOLD and THIS starts a new line" would appear in the display area (TextBox) like this.


    My string where this word is RED and this word is BOLD and


    THIS starts a new line


    I hope this helps


    Thanks Again


    albanello
     
  3. Hi Joel Thoms

    Thanks for your responce. I have not tried you suggestion yet but assuming it works where do I find the other codes to do the other formating like BOLD, Text size/color, font blah....blahand all the other types of text formating. Is it possible to change the color of say one word or a sentance ? Make a work bold or change the font in the middle of the string. I'm looking for HTML type control of content when I encode my text string for the Textbox. Remember the text strings are are all static and need to be assigned to myTextStr.text as a function of User input (Radio button selection).

    Thanks again
    albanello
     
  4. Albanello,
    I think I understand the question now. Since the visitors will not change the text itself, you shouldn't use a textbox, since this is an interactive control, meant to be used by the visitors. if you want to show some formatted content, just use a label or a literal control. All formatting then is done using html and/or stylesheets.
    For instance, if you put a label (MyLabel)on your page, in the "push radiobutton"-command, you might add something like :
     
  5. Albanello,
    If you really want to format your multiline textbox, you should consider the RichtTextBox component, which you can use for free at DiscountASP.NET. HTML textboxes like you are using aren't really meant to be formatted unless the complete textbox is formatted alike. Then you could use CSS (inline or through a stylesheet) to do the formatting.
     
  6. Hi all
    ASP.net Web Application
    Visual Studio 2003
    Visual Basic
    I want to format the text in a Multi line TextBox control. Depending on a user responce I display a different text string.
    I have tried:
    mytextbox.text = "This is a line of text \n This should be the next line of text"
    and
    mytextbox.text = "This is a line of textThis should be the next line of text"
    neither one will cause a line feed in the TextBox.
    HOW do I format text at run time. I would like to be able to use other formatting like BOLD, text color... and size !
    Thanks in advance
     
  7. Thanks steurm


    That makes more sence I'll try it tomorrow. Have a safe holiday


    albanello
     
  8. You should look into the a rich text box control. Most of them allow you to limit the functionality of the control, so if you only want to allow your users to access bold and colors, then you can limit them to just those methods. I've used freetextbox.com's control before and it was pretty simple to setup and use.

    If you don't want to use that, you will need to create your own custom "rich text box" like control. It will probably be more difficult than just using one of the free controls available online.

    good luck!


    Joel Thoms

    DiscountASP.NET
    http://www.DiscountASP.NET
     
  9. Thanks for your responce


    I don't think the rich text box is what I need. The user will NOT be inputing! I was using the text box to output Help text as a function of the radio button selected.


    Here is the Requirement:


    1) Must be able to Scroll


    2) Must be able to Change Text as result of radio button selection by user


    2) Must be able to Show/Hide


    3) Will only Output Text


    4) Would like to be able to format text ie: Color. Size....underline


    Someone else suggested a label but they are not Scrollable


    Any suggestion to satisfy the requirement will be appreciated


    albanello
     
  10. Hi Albanello,

    When I find I have requirements like yours, I almost always decide that it is not a good idea to have a scrollable area within the main page. If I were you, I would just use an asp:Label which has all of the requirements you listed, but it will expand the page. Users will be able to scroll the entire page if the label is long and expands the page.

    If you have your heart set on a scrollable area within your main page, I think the answer lies in an HTML component called iframe. I an iframe (inline frame) is a section of a page which has a set size and whose contents is dictated by another page. When the iframes contents expands past the size of an iframe, it will scroll. I would suggest you use an asp:Label to populate the contents of the iframe.

    Here is a nice example that is probably similar to what you are looking for:

    mercury.tvu.ac.uk/~lucieh/iframe.htm

    Good luck,

    Jeremy

    Post Edited (JerSchneid) : 12/27/2005 11:05:50 PM GMT
     
  11. Thanks JerSchneid


    I'll look into IFrames. Thats a idea I have not thought of I was tring to use a asp.net control.


    albanello
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page