How do you make buttons re sizable at run time? - c#

I want to make it so that my buttons change size based on the text inside them. Kind of like a Label with it's height and width set to "Auto", but I would like to start with a pre-determined dimension.
Is there a way to place a button, size it, and allow for re-sizing based on run-time text changes? If so, how do I do this?
I've looked at this example:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/188c196e-90d8-4584-bc62-38d7e008cf5c/how-do-i-resize-button-text-upon-button-resize
It has to do with inserting a textblock on top of the button, but when the text adjusts sometimes the new text becomes too small because the text does not wrap for some reason...
Thank you.

You can set the MinWidth and MinHeight properties so that you start with a predetermined size and the button will be able to grow with text.
Unfortunately this would not allow the button to get smaller.

You will need to size it based on its content, then. That is, have no XAML defined size.
Elements on the page normally size themselves to their children.

Related

Activereports shrink to fit issue- textboxes

In Activereports ver 7.0,
I have placed 2 textboxes one after another in vertical manner. I assigned particular width and height for both and then programmatically assigning text contents to both textboxes.
CanShrink property is set to true for both textboxes,so the textboxes can shrink to fit based on its contents.
My problem is once the first textbox shrink, I want to move the second one closely to the first one [To remove the extra space generated by shrinking], but it doesn't happen. Why is that?
Please check the image below
Because, the controls only move down, not up during report run. This is by design. In order to accomplish what you are doing, make the textbox1 size very small to begin with, so in essence it will always grow. In case if shrinks with not enough text you can use api to move the textbox2 up (use the location of that control in section format/before print event.

Window with dynamic size to keep its current size after loaded

I have a Window that has dynamic width and height and a user control as content.
Based on several conditions in my view model several controls of my user control are visible or not visible.
Using SizeToContent.WidthAndHeight nicely WPF make my window appears perfectly with the correct dimensions to fit everything that has to be visible according to my Bindings that take effect during Loaded event of my user control.
My problem is that I have a TextBox with no defined width where if the user types in too many characters it forces my Window to grow in width, and I don't want that!
Is there a way to avoid that without writing to much code and without loosing the functionality that if user resizes the window, everything in there change automatically to fit the new size?
What I want is that every control (or the window itself) will keep its current size and not to grow outside of current window's bounds.
I hope I made clear my problem and thank you in advance!
I think you are searching for the MaxWidth property of the TextBox, try to bind it to the Textbox-es parent controls Width and then if you type a longer text then it shouldn't grow larger.

How to auto adjust width of a wpf textbox?

I'd like my textbox to have a width that will fit exactly the size of the text within it.
So if there's just one character within it it'll be a small width.
And if there's a long word within it it'll be a long width, etc.
Is this possible, and if so-- how can I go about this?
That is the default behavior of a TextBox, however the parent panel for the TextBox can affect a TextBox's size.
For example, a Grid will automatically stretch it's children to fill all available space. A DockPanel will do the same with the Last Child added to it, unless LastChildFill=False.
You can overwrite this behavior in the parent panel by setting the HorizontalAlignment of the TextBox. For example, setting HorizontalAlignment="Center" will center the TextBox inside a Grid rather than stretching it to fill all remaining space
It depends on the container the TextBox is in, but typically if you set HorizontalAlignment="Left" you will get this behavior.
However, if it's (for example) the last element in the DockPanel with the LastChildFill property set to true, then the DockPanel will stretch it out for you.

width of the dropdown arrow

So in winforms, every dropdown combobox has this little arrow thingy to the right that tells the user it's a dropdown, kinda like this:
Now how do I figure out how wide that is in pixels? Reason is, I'm using ControlDrawToBitmap, this doesn't draw the text properly for the combo boxes, and I can redraw the contents, I just whack some of the arrows (which are drawn properly).
First idea that comes to mind: Check to see if the combobox button width tracks with the scrollbar width. The scrollbar width can be modified in user preferences. Use GetSystemMetrics() API to get the width of the various scrollbar pieces. If you change your system scrollbar width and it does not affect the size of a normal combobox, then ignore this.
Second idea: use the edit control's formatting rect to find out what the edit control thinks is the usable display area (minus the combo box). See EM_GETRECT in MSDN.
However, it sounds like this is just a hack workaround for your real problem: If you could get the controls to draw correctly to bitmap, then you wouldn't need this hackery.
I calculated it to be 9 pixels wide in photoshop

Multiple column scrolling, resizeable panel?

I have this:
Each list is its own WrapPanel and they are all on another WrapPanel which is in a ScrollViewer. If I don't set the height myself for the main WrapPanel it assumes I want the WrapPanel as high as it can go giving me only one column whereas I want as many columns as needed to fill the window.
If I set the Width and Height of the WrapPanel that holds everything to fixed numbers, but I want it to change when the user resizes the window.
In your example screen shot and description I see a tab control whose anchor is set to Top, Left, Bottom, and Right. The tab page with AutoScroll set to true. Within the tab page I see a FlowLayoutPanel. The FlowLayoutPanel has its AutoSize property set to true. I also see a set of other panels/user controls each of which contains a title and a series of check boxes.
You can`t achieve this with standard controls. You can try to create your own custom WrapPanel implementation. But, actually, looking at original WrapPanel sources I think this will be quite tricky. You see, what you want, is basically to measure how many columns can fit in the current window, while every element in column can be of any size. The way I see that algorithm, it will require N*N iterations to get the final result. So you may have problems with performance.

Categories

Resources