Best way to display multiple lines of static text in C#? - c#

I am making a prompt in C# that instructs the user how to use the program before they can access it.
What is the best way to display multiple lines of static text? Using a bunch labels doesn't seem like it would be the proper way... xD

Use a text input box marked as read-only and multi-line.

If you're using WinForms, you might want to consider adding a WebBrowser control to your form - you can then point the browser to an html file you send with the program. This allows you to use all of html to instruct your users, as well as point them to, say, your web site for more help or information.

One label can contain multiple lines of text if the text has newlines in it.

Related

Web automation using C# WebBrowser

I'm in the very early stages of attempting to automate data entry and collection from a website. I have a 16,000 line CSV file. For each line, I'd like to enter data from that line into a textarea on a webpage. The webpage can then perform some calculations with that data and spit out an answer that I'd collect. Specifically, on the webpage http://www.mirbase.org/search.shtml, I'd like to enter a sequence in the sequence text box at the bottom, press the "Search miRNAs" button and then collect results on the next page.
My plan as of right now is to use a C# WebBrowser. My understanding is that I can access the individual elements in the HtmlDocument either by id, name or coordinate. The last option is not ideal, because if I distribute this program to other people I can't be sure they'd be using at the same coordinates. As for the other 2 options, the textarea has a name, but it's the same as the form name, so I don't know how to access it. The button I'd like to click has neither a name nor an id.
Does anyone have any ideas as to how to access the elements I need? I am by no means set on this method, so if there's an easier/better way I'm certainly open to suggestions.
The WebBrowser class is not designed for this, hence why you are coming up with your problems.
You need to look into a tool that is designed for web automation.
Since you are using C#, Selenium has a wonderful set of C# bindings, and it can solve your problems because you'll be to use different locators (locating an element by a CSS selector or XPath specifically).
http://docs.seleniumhq.org/
Check mshtml - Mshtml on msdn
You can use it with the WebBrowser object.
Add Microsoft.mshtml reference to your project and the using mshtml declaration in your class.
Using mshtml you can easily set and get elements properties.

How to print dynamically-created HTML via c#?

I have HTML generated on a form. If you click a button, the HTML is generated and is currently placed in a ASP Textbox with just the text
<!doctype html><html>....</html>
and I want to automatically print this HTML (including the styling that is only for the generated body).
How can I do this?
To print your code you need to do several things
Tell the browser what to print, here's a few ideas, or create a new window with only the stuff to print.
Find a way to show the plain code, like using <pre> tags or the mentioned CodeMirror
Launch the print dialog, a simple javascript basically something like window.print()
There will be no automatic printing (unless you target IE with some black magic) as that would be insane to allow on the web.
I hope I understand your question correctly. CodeMirror is the one you might want to try. It displays and formats HTML text with colors.
http://codemirror.net/mode/htmlmixed/index.html
You will need to trigger the print request using Javascript, but you can set this off using C# (look at the ClientScriptManager for usage).
The window.print() function is what you need.
You will presumably want to restrict what you print, take a look at this SO post for ideas.

ASP.NET - Converting Text to an Image and Displaying on an ImageButton

I'm creating ImageButtons on an asp.net website. Sometimes, however, an image doesn't exist for the given text and in those cases, rather than display a 'broken image', I want to simply convert the string to an image and display that.
I've seen how to create a Bitmap/Image using C# and .NET from a text string, however, I'm not sure how to utilize this for an asp.net project. The ImageButton requires an ImageUrl...so what can I do when I'm trying to dynamically create the images? Is there a way to create them and save them someplace that I can then point to or a way to create and show the images that doesn't require their being saved?
Any tips on how this could be achieved would be very much appreciated. Thanks!
Certainly possible.
Dynamically Generating and Caching Images in ASP.NET with the GeneratedImage Control
Try using a LinkButton instead. You can use File.Exists to see if the file exists, you may have to use VirtualPathUtility.ToAppRelative if you need to find the applications path to that file. If the file does not exist, you can set the LinkButtons value to just the name of the textual representation, otherwise you can put an image tag (hopefully with its alt attribute set).
It's not generally considered good practice, but you could easily add a reference to Windows Forms and use GDI+. I've done this many times. Here's a link:
http://www.codeproject.com/Articles/1827/Web-Graphics-On-The-Fly-in-ASP-NET

Showing an XML file in a form with C#

it might sound stupid, but I need a way to take an XML file / string, and show it to a user in a form.
I'm currently trying to use the WebBrowser control, but its Document field is read only. I tried setting DocumentText instead but it seems to be accepting HTML only. What control should I use? It can be anything in WinForms or Infragistics.
Also, if there's a .NET XML parser, I'd love to know.
Thanks.
Give XmlVisualizer a try. Also you might want to take a look at the following posts:
http://www.dotnettutorials.com/tutorials/xml/winform-filter-xml-cs.aspx
Show XML file in WinForms app with IE-like coloring and collapsing nodes
Try setting the DocumentText instead. See this post for further details.
Load the document with XmlDocument.Load(). Then use XmlDocument.OuterXml...

Detecting hyperlinks in WPF RichTextBox

Hey folks, I'm wanting to write some rudimentary support for detecting hyperlinks in a WPF RichTextBox control. My plan is to use a regex to identify any links and then manually replace them with real hyperlink objects.
However the part I am having trouble with is getting the correct textpointers, etc. once I find a link. For example, I can flatten the entire document to a text string and find links, but once I do that how can I get the proper pointer to the block that needs url-ifying?
Perhaps a better approach would be to iterate over blocks in the document, assuming a url would not span multiple blocks, however even then I have very little experience working with the RichTextBox/FlowDocument object model so any pointers (pun intended) would be helpful. Thanks!
I think you might find this useful:
http://blogs.msdn.com/b/prajakta/archive/2006/10/17/autp-detecting-hyperlinks-in-richtextbox-part-i.aspx

Categories