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.
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.
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.
Related
I am currently porting my application from WPF to Cross-platform. In the WPF, I used a read-only richtextbox to show the result to user in order to show both IMAGE & TEXT. In Xamarin.Forms, Is there anything similar? Thanks.
There is no control in Xamarin Forms, hence you would have to use CustomRenderers and create your own.
However I only found one decent RichTextBox implementation in
UWP RichTextBox
This means that the only way to get any decent RichTextEditor, is to use a WebView, and load a WebBased rich text editor.
But since you want it as read-only, the simplest thing to do, is to scrap the idea of any RichTextBox, and just display the text and image as separate components in your mobile app.
You can use Spans, in a label to implement formatting within the label if needed.
I found the Telerik RichTextEditor for Xamarin a much better Rich Text Editor package for Xamarin Forms after trying out and evaluating a handful of other alternatives.
This is licensed software and you have to pay for using it.
Here's the link, https://docs.telerik.com/devtools/xamarin/controls/richtexteditor/richtexteditor-overview
ScrollView can be used like readonly richtextbox. I added the elements programmatically(label for text and image). It's also read-only so it met my requirements
Syncfusion's brand-new rich text editor control for Xamarin.Forms is available now. Check out the following article for more detail.
https://www.syncfusion.com/blogs/post/introducing-xamarin-forms-rich-text-editor.aspx
I have a web app in which I want to be able to highlight a word or two in a multi-line textbox, out of several paragraphs of text, and have a button click method manipulate the selected text.
I want to be able to store the selected text in a variable but I haven't been able to find a way to get highlighted text in System.Web.
I know that System.Windows textboxes have the SelectedText property which would be perfect, but unfortunately I don't know how to use anything but the asp.net framework with html pages and c# code behind.
Basically what I am after is an equivalent of TextBox.SelectedText that I can use in a web app, or an alternate route which will accomplish the same result.
The user will be writing the content into the textbox so suggested different controls need to be editable.
I have tried incorporating Javascript into my C# code but it proved too complicated for me, and I don't know how to create a solely javascript web app.
Thank you for your answers so far
I am coding a Windows Forms Application in C#, and one of the requirements is to display some html code in a control, with the correct colors that correspond to the relevant tags.
E.g. When right clicking on a webpage in Google Chrome, then selecting View Page Source, a form is shown with all the html, correctly formatted, with tag colors and each line of code's line number.
Is there a free, reliable control that can do this? Is there an inbuilt Microsoft control that does this?
As I am new to this area of coding, can someone please provide me with some useful names, and some resource links if possible? I am not sure of the correct name for a control that does this, and as such, my Google searches have not come up with what I am looking for.
Also, the control needs to be trustworthy.
Thanks
You can try ScintillaNET control. It's open source and has HTML syntax highlighting as well as many other features.
I am wondering does anyone know if it is possible to render html in a mobile 6 form? The only way I can think that may work is the internal web browser control.
I am wondering is there a better way? I am thinking if I go the path of web browser control I will have to generate an html file then insert the code I want into this file.
I need something like this because I am pulling in some text that can possibly be formatted with html stuff such as font weight.
A Browser Control is really the only way (unless you want to parse the HTML yourself and turn it into rich text for an RTF control, or worse, manually handle it all yourself).
As people have said you do need 2 controls, but it might be possible to hide the regular textbox (maybe behind the browser control) will still leaving it editable.
In this case although it would be controlled underneath with code like <b>mytext</b>, the user would never see that giving them some illusion of a WYSIWYG editor (though I can already imagine a few problems you might come into attempting this)
I have written an HTML edit control for .NET.
It doesn't currently support Windows Mobile: but I have Windows Mobile development experience myself, and I might be able to port it to the Compact Framework, if you would be willing to pay for that, as explained in the Developing New Functionality section.
How can I put a link in a C# TextBox? I have tried to put HTML tags in the box but instead of showing a link it shows the entire HTML tag. Can this be done with a TextBox?
Use the RichTextBox, no need to build your own, it cames with VS
I would try using an editable div and making it look like a text box. This would allow you to get user input and use links.
To make this easier, try JEditable.
If that is in windows forms and you really can't use the richtextbox, you can create a control with a linklabel inside of textbox.
http://www.codeproject.com/KB/miscctrl/LinkTextBox.aspx
I would think about this a little bit. If you allow executable code in an editable control, the user, the user can execute ANY code. This is generally a bad idea.
The behavior of the C# control is intentional to prevent the exact behavior that you are trying to create. A little creativity (such as parsing out links from the text box and creating a list of links next or below the text box) will provide a much safer application.
To my knowledge not with the standard textbox. You'd have to create your own. One option it the Telerik controls, they're a little pricey for individual development, but very robust and configurable.
For windows application, we can use a webbrowser control. However, for web applications Freetextbox will do the job.This is freely available dll.