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.
Related
I have developed a winform application. It has a listview with multiple columns having different texts. Initially, I have set the column width = -2 to take the size of longest text in the column.
The issue is that sometime text overshoots the laptop screen and a horizontal scroll bar appeared in the list view.
To fit all the columns in a screen, I manually modified the columns widths using column boundaries in the GUI. When I modify the column width, the column text starts disappearing from right. I want it to disappeared from left.
I have searched goggle a lot but did not find the answer.
Question might look weird or may be I have not explained it properly. Please let me know if more information is needed.
Thanks in advance.
The Listbox columns in Windows Forms are not exactly a high level control, I've used it some times but just for simple lists, It certainly has not a builtin function to make what you want, to obtain it you probably need to subclass the control, create a new class for the item managed in the list and write some code to perform what you need.
I think you can find some hints on how to achieve all this in Charles Petzold book about windows forms where he shows how to measure a string and how to draw directly on your control.
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.
I have these DataGridViews, used pretty heavily in my app to show lists of child or summary data. The column widths are set to handle most cases, and to fit in the default size of the UserControls that directly contain and manage the DGVs (the UserControl also contains a title, sum of records, and a Refresh button).
I would like to give the user a menu option in one screen that has a LOT of DGVs, that would basically replicate the behavior they'd get if they double-clicked on the right border of each column header they saw. The default behavior in that case is to resize that column so that all text of all cells in the column is shown. This is a freebie of using DGVs, but I'd like to plug into it to do the same thing on a wider scale.
I DO NOT want to set the AutoSize property of the columns or DGVs; if a column is resized and the user wants to further adjust it, they should be able to. There has to be a way to do this without locking the column widths to what AutoSize thinks is necessary.
OK, finally I found it:
dataGridView.AutoResizeColumn(col.Index, DataGridViewAutoSizeColumnMode.AllCells);
or if you prefer to resize all columns in one shot:
dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnMode.AllCells);
I am developing in C# and .Net 2.0. I have a user control that draws cells (columnar) depending upon the maximum number of cells. There are some drawing routines that generate the necessary cells. There is a property NumberOfCells that adjust the height of this control; CELLHEIGHT_CONSTANT * NumberOfCells. The OnPaint() method is overridden (code that draws the Number of cells).
There is another user control that contains a panel which contains the userControl1 from above. There is a property NumberCells that changes userControl1's NumberOfCells.
UserControl2 is then placed on a windows form. On that form there is a NumericUpDown control (only increments from 1). When the user increments by 1, I adjust the VerticalScroll.Maximum by 1 as well.
Everything works well and good BUT when I increment once, the panel updates fine (inserts a vertical scrolll when necessary) but cells are not being added! I've tried Invalidating on userControl2 AND on the form but nothing seems to draw the newly added cells.
Any assistance is appreciated. Thank you in advance.
Lawrence
Try debugging and check that the NumberOfCells property is properly being set. If it is and the cells still do not show after the window has invalidated (say, by minimizing then restoring the window), you have a problem with your cell-drawing method.
If after minimizing/restoring the cells show up, you need to call Invalidate(CellRegion) in the setter for NumberOfCells
Are you resizing the controls when you add columns? If they are not big enough to show their entire contents, then they will simply clip them and you may not see any new column(s) that have been added.
I'm adding some textboxes to a form dynamically at runtime. Everything works fine i.e. the textboxes are aligned, anchored and automatically resizes until the form is maximized. On maximizing the form, the textboxes are added to the same location while the form was not maximized. This causes a misalignment of the textboxes.
How can I ensure that all the textboxes are at the same location and of the same size both while the windowstate is normal as well as maximized?
EDIT:
Btw I'm using C#
EDIT:
Would a flowlayoutpanel be useful here?
It's a quite old question, but maybe i'm able to answer it.
After reading all your comments, i think i can summarize your problem to this:
You have a form at a specific size and add some controls at runtime at a specific location with anchor set to Top | Right.
If you just display the form and let the controls appear everything works fine
If you maximize your form (or change the size of it) your controls won't be appear anymore at the correct location you want.
To get rid of this problem you can try some different approaches:
Use a FlowLayoutPanel, take care for the FlowDirection and maybe just create all your needed controls beforehand and just toggle the visible state.
Use correct values for the location of your newly created controls.
The second point is the error you have (i think). You found someway to calculate the location of your control if your form has it's original size. To get the correct position if the size of the form has changed (e.g. maximized) you have to consider several factors.
The delta values from your default size to your current size.
The Anchor(s) you wish to set on your control.
In your case you'd like to put a control which is anchored Top | Right, but the location is set by Top | Left. In that case you have to calculate the difference between the control.location.x and the form.width in it's default size. Then you take this difference and subtract it from the form current width. Now you can place your control at this position (cause Top never changes through a resizing). If you have a Anchor at Bottom | Right you have to calculate the same with control.location.y and form.height.
The behaviour and calculation if no anchor, for Top | Bottom or Left | Right are set is left as an exercise to the reader. ;-)
Last but not least there is also another hacky way to get your control at the right position:
If you like to place a new control somewhere change the Form.Visible to false
Save the form state, size and location
Change them to your default values
Add the controls you want
Restore the formerly saved values
Make the form visible again.
The Anchor property specifies which borders the controls should ensure they're always the same distance from. It can get pretty confusing, which is why you're seeing things shift around when anchored to the right border.
If you just want to ensure that the textbox display stays consistent relative to itself, I'd suggest putting down a Panel, with anchoring on the Panel, and then adding textboxes to the Panel. The X and Y coordinates on your text boxes become relative to the Panel, so it's a lot easier to do layout especially when the location of the Panel suddenly changes.