Changing C# Coordinate System to be RtL - c#

I have a dozen of code editors written in Left-to-Right layout (for LTR languages).
I'm thinking if I could change C# coordinate system so that x = 0 being at the right rather than left, then I would not change any code written to render LTR.
Is this possible in .NET? Thanks

I'm probably missing something obvious but I don't see how changing a coordinate axis is going to help you in this case.
If you are not after proper support for RTL languages then realigning all text controls to have the text Right Aligned would be sufficient.
But editable controls where user input is expected would also need to output the text in reverse order. The caret would need to move along the X axis toward the -ve side. To support this you would probably need to do some code changes in the controls internals.
Personally, I've never seen a RTL controls that would simply flip an axis to switch from LTR mode.
My two cents.

Related

Check if Control.Text is to long to be shown

I'm trying to do some automatic tests if the strings of a translated Application still fits the existing UI. The translation process just takes an existing resource assembly translates the contained resources and creates a new resources assembly for the new language. Easy but that way there is no garantee that the translations still fits into the UI (the UI is not involved in the translation process) and might get truncated all over the place. So for an automatic check i would need an idea on how to find truncated Text on the UI.
I tried so far:
Measuring the client size of a control, measuring the text length and
compare them. Doesn't work since there seem to be no way to find out
the ~real~ client size of a control that is used for putting text on
it (For a Button its not just Size minus Padding for example)
Setting AutoSize to true and checking if the control grows. That
would only work for non-wordwrapping controls and there seem to be
no sharp limit here. A control might grow to fit the Text on its
surface when setting autosize but the Text was fitting before
also. The margins might have been pretty narrow but the Text where
fitting.
Are there more idea that might work? Or are there some tweeks that might make the above mentioned ways work? Would be great if there where a simple Win API method i could call that would just give me the actual shown text of a control not the text a programmer/programm whishes to be shown on a control.
Get the amount of the characters from the non translated version and differentiate them against the length of the translated version then multiply the current controls width by the difference. It could look something like this.
float scalingAmount = 0.1 //This is just an example value, you'd probably want to adjust this yourself
float difference = oldLabel.Text.Length - label.Text.Length;
label.Width = oldLabel.Width * (difference/scalingAmmount)

Text using Cambria Math font in Windows forms gets shifted vertically [duplicate]

I wanted to show some mathematical expressions in a winforms textbox. So I thought the "Cambria Math" font would be a good choice but the text looked strange due the high top and bottom margin of the font. First I thought I made a mistake but according to this question, it's the correct behavior of the font.
Why does Cambria Math have these big margin values and how can I display my string correctly in the textbox like Word 2010?
(Note that I know only a little bit about typography ;)
Edit: I had to make the textbox that tall otherwise the caret would be invisible. The font size of the textbox is set to 8.25pt
Cambria Math uses Microsoft's mathematical OpenType extensions.
Word 2007 and later understand these and display the text with reasonable spacing.
However, notepad and Word 2000 display the text with enormous spacing, just like winforms. I guess the font has this much space by default because some characters (like U+2320, top half integral) are much larger than the alphanumerics.
If you use Cambria Math with a font engine (such as the one used by winforms) that doesn't understand the math extensions, you're going to get the big spacing.
If you're displaying simple expressions you might as well use Cambria.

How to write quadratic equation on Label in C# WinForms?

We are making statistical software. Everywhere we need to put formula such as ax2+bx+c How to make ax2 means x square 2. I want to display 2 on upper side of x. Same with πc I want to display c at suffix.
Do you have a fixed list of formulas that users can choose but cannot edit? Then generate an image for each formula, store them in your application, and display them in a PictureBox.
If you expect users to be able to type in arbitrary formulas and render them interactively, you will have to implement a visual formula editor control. These controls take markup such as MathML or TeX and render them as graphics. Several are described in the link I provided, but I do not know of any such .Net controls for WinForms.
for the "upper" 2 and 3 there are symbols: a², a³ (even on a german keyboard but you will find them in your symboltable in windows too) - the lower c will be harder - I would consider using pictures for those more complex formulas (if you need dynamic formulas it you might have to create them with Graphics in code)

Want to bold few characters of a word get bold in treenode in winforms using c#

i have "search TextBox" to search in treeview, i give result very well. But i want to get those parts get Bold which i typed in "search TextBox" of my winform.
Ex: i Typed Ram then it gives *Ram*esh .
The TreeNode class doesn't support that, its Text is always drawn with one font, the TreeView.Font. Making parts of the text bold is technically possible but very hard to get right. You need to enable custom drawing with the TreeView.DrawMode property and DrawItem event, there's a good example of it in the MSDN Library article.
That's the easy part, the hard problem is that the node is too small to fit the text after you draw parts of it in a bold font. TreeView is missing a "MeasureNodeText" event that would allow you to ask for enough space. The only workaround for that is to lie about the node text and make it artificially wider by prefixing characters. Which you then don't draw in the DrawItem event. Very hard to get consistently right, you'll want to consider a fixed pitch font instead.
I cannot recommend you pursue this unless the feature is really important to you. This otherwise explains why you never see this feature in other programs. Consider changing the color instead of the font weight too. Still hard to glue the pieces together btw.

Getting whole numbers from MouseEventArgs.GetPosition()?

I'm getting floating point values like (471, 326.723333333333) from calling MouseEventArgs.GetPosition() on my border control. While I can always round the numbers manually, I was wondering if there's some kind of setting to get whole numbers.
I thought putting SnapsToDevicePixels to True on my border control would help but it doesn't, as it's probably unrelated.
Any ideas?
Thanks!
In WPF, you'll always have positioning returned in floating point values. If you want to round it, you'll need to do this manually.
This is due to the resolution independence, and is by design.
Since WPF is device-independent and not all devices share the same pixel sizes passing MouseEvents with fractional coordinates makes sense (also you can put controls in 3D space where the whole coordinate system translation stuff won't happen with integral pixel values).
SnapsToDevicePixels is just a property controlling how a control is displayed and that edges and straight lines preferrably lie on complete pixels than in between. It has nothing to do with how mouse events are handled (as you also have noticed).
As a general rule of thumb, everything in WPF is measured in double values, so either live with it (you checks would likely be the same anyway) or continue rounding to int if you like so :-)
Positioning from your mouse is continuous. Positioning on your monitor is discrete. The coordinate values you're getting are better than what you need and rounding will always give you the closest pixels. Basically, round it and don't worry about it.

Categories

Resources