I have a string to draw in a custom dialog box. How can i get the required length of string in pixels using WPF?
If you want to show it afterwards within a TextBlock, create the TextBlock and call Measure and Arrange. Make sure that the TextBlock has set the right font size before calling Measure.
Another way is to go via FormattedText, if you want to do your calculations on a low level.
You might not need the (pixel) size.
It might be better to automatically size the dialog to its content.
Related
I am using the standard textbox control on a Windows form. I want to display the text VERTICALLY rather than horizontally. To accomplish this I set the multiline property to true, the TextAligh property to center and used the lines property to input each character as a separate array element. So far, so good.
I see the text displayed the way I want but would like to reduce the vertical spacing between lines without reducing the font size. Can it be done? If so, how?
It can be done, but not by the default options on a standard textbox.
You would probably need to override the Paint event and draw the text yourself, but it would get very ugly, and would essentially be reinventing the standard Paint method.
How can I automatically scale text inside a control based on the control's size but always make sure it's readable (that is, I want the font size stays between 9pt and 30pt)
The ViewBox can help with this, but I'm not sure about keeping the font size within a range. You can probably accomplish this roughly with MinHeight and MinWidth.
Try to use ScaleTransform.
In order to understand how to calculate the scale size you may refer to http://social.msdn.microsoft.com/forums/en-US/wpf/thread/d73c9eb2-9c68-428d-b99b-d23d0c62c095/
I'm trying to size a checkboxlist control to 500,250 from its current 502,251 (It's an OCD thing) but every time I try, it just reverts to 502,251.
Is it because the parent container is docked in the window? Are there any workarounds?
(This is through the visual designer)
Most likely the control is being resized due to the control's font size. The ListControl does not like to display an item that will be "split" by the bottom edge, so it will resize the height. Try changing the control's font size and adjust again to verify.
No work around, and you really do not what one, because the control is really doing the right thing.
Yes, it is OCD. I have it also, but this one you have to let go. :O) Consider yourself lucky because you are only one or two pixels off. I was five pixels off once, and I had to put a note on my monitor to ignore it. It so bothered me.
hi I have RichTextBox bind to description(html format) from database and it is read only. I just need to show First line from description. How to achieve this
As Silverlight has no way of measuring the width of fonts, you'll need to take an arbitrary amount of the text, and simply Substring() it.
A client has asked for a display to flick over like an airport display screen, ie each row flicks over when information changes.
I am not sure which is the best control to use, or the method of getting each row to transform one after the other.
any suggestions woul b gratfully accepted
John
Here's what I would do in general concept..
Make a regular panel of, say 50px high. (This is arbitrary but this panel just holds the size in place so the control doesn't shrink with its contents.)
Create a panel inside that one that will be the 'animated' panel.
When it's time for information to animate, create a storyboard that uses a transformation to "stretch" the height down to 0, change the content to the updated information, then tranform stretch the height back to 50px. This will create the illusion that the panel is flipping over.
If you make this a user control, then you could simply add however many "rows" you needed of this control to a StackPanel to make your screen.
The best way of representing this effect easily is to randomize the text during the change.
Patrick Long implemented this effect as a custom animation here