1

Does anyone know how I would show code in a textbox in c#? I am importing the code from a spreadsheet into sql server. Then I need to pull the code out of sql server and store it in a textbox but the spacing is off when I display it and it is hard to read.

Is there any controls or functions that help with this?

Any help is much appreciated.

Edit* This is for a windows form application.

4
  • What does the spacing has to do with the text in the TextBox? Commented Jul 8, 2014 at 13:51
  • I'm not sure what you mean. For example, if I were to post code in this forum I would use code tags to preserve format. Is there a way I can do that in C#? even if its not a textbox? Commented Jul 8, 2014 at 13:53
  • 2
    It seems to be the usual problem with variable width fonts. Set the textbox font to a fixed width font like Consola Commented Jul 8, 2014 at 13:53
  • Web or windows app? there's a difference... Commented Jul 8, 2014 at 14:01

2 Answers 2

1

For a Windows Form application if you really need some formatting you should use a RichTextBox

With the RichTextBox control, the user can enter and edit text. The control also provides more advanced formatting features than the standard TextBox control. Text can be assigned directly to the control, or can be loaded from a rich text format (RTF) or plain text file. The text within the control can be assigned character and paragraph formatting.

Sign up to request clarification or add additional context in comments.

Comments

1

Is this for a web application or a Windows application? There are plugins that do just that for web-based apps.

For instance, I use SyntaxHighlighter by Alex Gorbatchev. It uses javascript so it's not specific to C# or any other language. You can configure it to color different languages e.g., in your case, SQL.

1 Comment

Ah thanks for your answer its for a windows application though. Forgot to specify.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.