Using superscript in C# resource file - c#

I have some superscript text that I need to define in a C# UI project resource file that will eventually be put in a XAML datatable.
For instance the 2 in this example needs to be superscript: (kg/m2)
Is there any way to define this right in the Value field of the Resource string...perhaps via a Unicode or HTML tag that a standard Xaml control bound to this value could parse?
I'm not opposed to using a XAML converter, but short of putting some sort of hacky string in the resource (e.g.(kg/mSQUARED)) and using the XAML to look for it, I can't think of an elegant way to that either.
Thanks!

Based on your comment above, it sounds like "squared" is the only one you need. So, to amplify my comment:
There's already a Unicode code point for "squared" aka "SUPERSCRIPT TWO". It's called U+00B2, if you want to Google more information about it.
Here it is:
²
Highlight that character in your Web browser, copy it to the clipboard, and paste it into your resource file.

Use US International keyboard layout, Press Alt-Gr + 2, that will show
Alt-Gr + 3 = ³

Related

RTF text font/color changing [duplicate]

I want to create a simple editor like Notepad++ with simple functionality... I need to color a specific word in the rich text box area. How can I do that?
For example: when the user write these word, I want to color them to the blue color. These words are: for, while, if, try, etc.
How can I make the richtextbox to select a specific word and then color them?
And, if I want to make a comment and color everything after the //, how is that done in the richtextbox?
How do I number the line in the text box, so I can now the line number when I'm coding in my editor?
Here's some code you can build on in order to achieve the functionality you want.
private void ColourRrbText(RichTextBox rtb)
{
Regex regExp = new Regex("\b(For|Next|If|Then)\b");
foreach (Match match in regExp.Matches(rtb.Text))
{
rtb.Select(match.Index, match.Length);
rtb.SelectionColor = Color.Blue;
}
}
The CodeProject article Enabling syntax highlighting in a RichTextBox shows how to use RegEx in a RichTextBox to perform syntax highlighting. Specifically, look at the SyntaxRichtTextBox.cs for the implementation.
In general, you have to work on the selection in RichTextBox. You can manipulate the current selection using the Find method or using SelectionStart and SelectionLength properties. Then you can change properties of selected text using SelectionXXX properties. For example, SelectionColor would set the color of current selection, etc. So you have to parse text in richtextbox and then select part of texts and change their properties as per your requirements.
Writing a good text editor using RichTextBox can be quite cumbersome. You should use some library such as Scintilla for that. Have a look at ScintillaNet, a .NET wrapper over Scintilla.
Did you know that Notepad++ uses Scintilla?
You actually do not have to reinvent the wheel by going through all the trouble as there is a .NET port of Scintilla named ScintillaNET which you can freely embed in your application as the source code editor :)
But to answer your question, there are few parts that you need to understand
Finding what to color
When to color
How to color
For the first part, there may be different approaches, but I think using regular expressions would be a good choice. I am sorry, but I don't know regular expressions much so I cannot help you in that case.
When to color is very crucial and if you do it wrong, your application will suffer a heavy performance penalty. I suggest you refer to XPath Visualizer which was done by our own Stack Overflow member, Cheeso. Take a look at the source on how the coloring of the syntax was done. But if you ScintillaNET, everything would be taken care of. Anyway, I really can't seem to find this documentation where he clearly showed how the coloring of the text was done. I would most definitely post it here if I find it.
The third question I think is covered by VinayC. But basically you use SelectionColor along with SelectionStart.
here is a good link on c-sharpcorner.com website on basic richtextbox syntax highlighting. I assume that you and any one visiting this page for similar problem want to do it for learning purpose. But if any one wants to do it for some making some comercial level IDE then it must use scintilla or some similar.
An other approach for this is to directly change the RTF of the richtextbox. Look in codeproject.com there are lot of articles similar to this problem.
I had some problems with that and here is my solution, beats me why it has to be done like this, but it works:
// position on end of control...
richTextBox.UpdateLayout();
richTextBox.ScrollToEnd();
richTextBox.UpdateLayout();
// ...then select text and it will be position on top of control.
richTextBox.Focus();
richTextBox.Selection.Select(foundRange.Start, foundRange.End);
richTextBox.BringIntoView();
Vb.net implementation
Imports System.Text.RegularExpressions
Private Sub formatString()
Dim rg =New Regex("\b(for|while|if|try)\b")
Dim m As Match
For Each m In rg.Matches(RichTextBox1.Text)
RichTextBox1.Select(m.Index,m.Length)
RichTextBox1.SelectionColor=Color.Green
Next
End Sub

Best method or control to display text from a file in an asp.net webpage

This may be a totally newbie question, but here it goes. I have a asp.net web page that I need to display text from a .txt file. I am trying to figure what would be the best control to do this with or the best method. I looked at using an iframe, but this does a very poor job of displaying the text from the file (for instance no word wrap for an iframe). I don't really expect anyone to solve this for me completely, but if you have any suggestions or know of any links to tutorials or explanations where someone has done this, I would be very greatful.
Thanks
You can for example add a Literal control, assign File.ReadAllLines("yourfile.txt") to the Text property and replace \r\n with <br />.
You should just read the text-file in code (using a streamreader for example). Once you have that text, just output it to your web page.
If you're using web forms you could place a label and then set the text of that label.
If you're using MVC you could put it in the ViewBag and then in your view output the value from the ViewBag (or use a custom viewmodel)
You could use a Literal or Label control. Make sure that the control that you use encodes the text in order to avoid XSS vulnerabilities (or encode the text manually if necessary).
It might as well be necessary to substitute line endings with <br/> tags.

Windows-Store-App RichEditBox Markdown Highlighting

at the moment I'm trying to get into Windows Store App Development and I'm stuck at some point.
I want to implement sort of a "markdown language" like the one on stackoverflow to highlight certain parts of text input.
Besides that I want to give the user the ability to use different font colors on his text.
The RichEditBox seems to be the ideal control for this task, but I don't know how to detect markup entering on the fly.
For example when the user enters **Test** the text should be transformed to Test immediately.
I have tried to approach this by listening to the "TextChanged" event and looking if the user enters **. If this is the case and if he entered the sequence ** already one time before, then I'm setting the character format of the text range from the end of the first annotation sequence (start marker) to the beginning of the second (close marker) annotation to bold.
But this solutions seems to be very quick and dirty.
My second thought was to use the WebView control to render the text after preprocessing it with "Markdown Sharp".
But then the user won't be able to edit text.
So I need to get some advice or tip on approaching this problem. I also looked into writing a custom RichEditBox control, but I have no experience in custom control development and there aren't that many resources on the web for Windows 8 development for now.
Thanks in advance.
As I see it, your problem is that you want to edit the "source" based on Markdown syntax AND show the formatted result in the same place. How would you revert Test to regular, as long as the asterisks are gone? If the answer is "using a button" then why not use the button to make it bold in first place?
However, you could do a hybrid thing: apply formatting in the source text, while maintaining the Markdown markup (not sure if this is entirely doable for all Markdown tricks, though). That is, **Test** would look in the source like **Test**. For the final, formatted result you would use a separate view, such as RichTextBlock.
In order to do the hybrid formatting, an option would be to have a background thread matching regularly the whole text against regular expressions specific to the Markdown syntax. For each match the corresponding text range would then be formatted accordingly.

Repeater Vs String Builder

I think the question may seem a little weird, but here's the details.
The Goal : To retrieve a set of pairs (text, value) for various reasons. one example for that of them is retrieving the alphabet, each letter will be used as an anchor or a LinkButton, the text value will be the letter and the click event will take the value part of the pair and place it in a stringFormat() to form a "Parametrized URL"
I've used two approaches for this goal but I don't know which is better!
1. Using a Repeater
A repeater that will have a LinkButton in it's ItemTemplate and through this blocks and will set the text to the 'text' and using eval and the 'value' to create the QueryString.
2. Using StringBuilder
Create an instance of StringBuilder
Use a loop with a counter equal to the total pairs to be retrieved. and append a certain string format that will build a long string with all the needed anchors for navigation using some code like this
Links_strngBuilder.Append(string.Format("<a href='/data.aspx?page={0}'>{0}</a>", chrctr))
and finally convert the String Builder instance to a string and assign it to a label
Note: the chrctr text and value fields will be retrieved as you suggest [in each loop from the database] or [loaded in an array/arrayList/List<> to store the values and save all those connections to the db]
Where i work we will never use a stringbuild becouse of the designer. We dont want the designer in the codebehind if he has to make a simple change. so keep the markup in the view and codebehind in the codebehind.
Edit
Other advantage of repeater is the change of cycle is much easier. No need to recompile and perhaps redeploy the tweak the UI, just edit the ASPX template, save and refresh.
I don't know anything about how these two approaches perform (in terms of memory usage and speed) comparing to each other but I'd definitely go for Repeater because:
The code is much easier to understand & support
Using a StringBuilder reminds me the days of the classic ASP when the Response.Write was used widely.
You can't use any of the benefits of the Visual Designer with a StringBuilder.
-- Pavel
I think building the output fits more in client side(e.g. when you do an ajax call and want to show the results in html) than server side except when your build a custom server control.
In addition, if you use the repeater you have the extensibility option whenever requirements changed, and you have more control and facilities(like event handling and styling with css and so forth).

How to send values from text box through form in "Group Sort Expert"dailogue in crystal report

alt text http://img136.imageshack.us/img136/4083/15748429.jpg
Hi all,
Please look into the above screenshot. Here i want to change the value of N in Group Sort Expert explicitly from text box using some c# application.
Can anyone help me on this.
I don't think that would be very easy. My guess is you'd have to hack into ReportDocument.ReportDefinition and maybe somewhere in the Areas or Sections collections. If you did find it and changed the value, you might even have to re-save the .rpt file for it to take effect. I'm not sure if it could be changed on the fly.

Categories