Is there any difference between WPF TextBlock and TextBox? - wpf

What criteria must I consider when selecting one of these two controls?

Common to both TextBlocks and TextBoxes:
Can be used to display text
Can be set to specific Height and Width or be set to Auto so that they grow in size with the text.
Can set font size, font type, font styling, to wrap and to range left, right or centred.
Can have opacity set and have Pixel Shaders applied.
TextBlock:
Used for displaying text more focused typographically.
Can contain text set to different colors, fonts and sizes.
The line height can also be increased from the default setting to give more space between each line of text.
Text inside a TextBlock cannot be made selectable by the user.
TextBox:
Used for displaying text more focused for content input or when content is needed to be made selectable by the user.
Can only be set to one colour, one font size, one font type etc.
Have fixed Line Spacing.
Can also be set to a fixed height and width but also have scrollbars switched on to allow content to expand.

TextBlock is more lightweight control for displaying text and TextBox is used when you require user input or edit existing text. Proof for mem usage.

Related

textbox padding in winform application

I want to set the position of my text in textbox and I don not know how, since there is no 'padding' property I can change. I don not want use panel to adjust my text
is there any other way? can I change the font margin in font editor software like fontCreator?

How do I auto resize a label's text in WPF?

I put my label inside a two-column grid and set its size to auto and when I run my application, the label's size grows if I maximize it (I'm sure it grows because I've put a background color and the background color also resizes to accommodate the entire two-column grid it's been placed into. My problem is that the label's text itself doesn't grow and stays the same 9pt. Am I missing a property option to set my Label's text to also auto-resize?
I've read tutorials doing this with a viewbox and a textblock and although it works, I've had trouble setting it up in two columns as it resizes weirdly when I run the application despite setting it up right.
Okay I finally did it. What I did was use the Viewbox + Textblock and I've put a border around the viewbox and set its background accordingly and had the textblock's background to none and now it's working as I wanted it to.
The problem I had back then was I didn't know how to put a background color on the viewbox so I tried a remedy wherein I changed the textblock's background but the problem was the textblock has its own size and even if I stretch it, it would only encompass the width of the text and not the whole viewbox.

DevExpress MemoEdit layout issue

I want to show some text inside the MemoEdit in two columns. The parse of the text works correctly because when I see the parsed text inside Notepad or when I debug it inside Visual Studio it shows it in two columns, so the text is formatted exactly in the way I need it. The problem is that when it is shown inside the MemoEdit, it doesn't keep the format (I think this is because it uses a different font for the text, not a fixed size width font, because white spaces are smaller then normal characters). I changed the font to some fixed size width font and is showing it correctly, but the problem is that I need to have the same font like the application uses. Is there any property on MemoEdit that can help me achive the behavior I want without changing the font?
Thanks a lot!
You can activate the RowAutoHeight option of the GridView.OptionsView property in GUI and you can set it pragmatically as below:
gridView1.OptionsView.RowAutoHeight = true;
You can also use CalcRowHeight event handler to tweak the height of the gridview rows. check the reference links.
Reference these DevExpress fourm thread -
Auto-height of grid rows and text WordWrap
GridControl row height (cell height)
Changing row height at runtime

How to resize multiple WPF controls when the text size changes?

What's the correct pattern to resize controls when a font size changes?
For example, I used the WPF designer to make a form, and placed UI elements from the toolbox. Late in the game I got the requirement that the font size of every UI element needs to be configurable, so now I'm thinking there has to be a better way to resize controls when the font size changes. Right now I'm doing alot of code behind calculations on Margin properties.
For such cases I usually place my control inside Grids and StackPanels, this way font size won't affect the layout, everything will be stretchable.
Never place controls on the Window using absolute coordinates.
Make sure your Height and Width on the controls are set to Auto.
When you use the designer/toolbox to add controls it usually provides a static height/width. If you type the tag in the XAML editor you get the control default which is usually Auto.
You'll notice the black diamond in the property window next to the attributes that are changed from their default value. You can right click and choose reset value to clear the attribute from your XAML and see what the default value is.

How to determine width of a windows forms controls whose width was increased because it is Anchored?

I currently have a Textbox on a Windows Forms, and I need to dynamically add a PictureBox box control at the right of the Textbox.
I create the PictureBox programmatically and I when setting the location of the PictureBox, i'm setting like this:
pBox.Location = new Point(tbControl.Location.X + ctrl.Width, ctrl.Location.Y);
So i'm setting the picture box to be located at the X location of the textbox PLUS the width of the textbox. However, since the textbox has an anchor property set to right, its width increases to fill the space between itself and the form border.
Problem is, that even though the textbox's width is visually bigger than the actual value of Textbox.Width. the Width property is not taking into account the extra width of being anchored.
I already tried properties like Textbox.Bounds.Width, Textbox.ClientSize.Width, Textbox.DisplayRectangle.Width, etc. with no luck. All of those properties return the original Width of the control without taking into account the resized width due to the Anchor property.
Does anyone know how I can determine the real size of the textbox? Thank you
The Width property always tracks the current width of a control, whether it is anchored or not. However, the TextBox is going to grow when you make the container larger and that will make it overlap the PictureBox. You have to anchor the PB to the right as well.
These should be returning the adjusted size. Either you are referring to the wrong textbox, or you are doing the query before the size has actually changed.

Resources