Dynamically size images in SQL Server Reporting Services - sql-server

My goal is to have a list of items each item has an image beside it whose size is proportional to some number from a dataset. For example, a list of countries which includes an image of a person whose size is proportional to the population.
How can I dynamically specify the size of an image based on data from the dataset?
Two approaches which don't seem to work:
(1) specify an expression for the image size (that doesn't seem to fit).
(2) tell the image to fit container and set the size of the container to an expression.
I don't want to resort to storing 100 images of varying sizes.
Are there any better solutions?

The trick is to use the "Padding" values of a cell or an image. These can be set with an expression, and will be the white space around your image.
For example, set right padding to
=RowNumber("DataSet").ToString() &"pt"
and you will get an image that gets smaller on each row.
Hope this helps...

Related

Mail merge picture size using Gembox Document

I’m using the mailmerge feature of Gembox.Document to produce reports.
I’m having issues with the sizing of a picture.
I have created a merge field inside a table cell, and I would like the picture to occupy the maximum of the cell size without changing it’s aspect ratio.
For now it’s inserting the picture, but the ratio is all messed up.
I’ve read in the help page that I could put a shape my merge field but after many attempts I don’t know how to do it, when I try to draw the shape in my word template, it doesn’t go inside my merge field.
Can anybody help me with this ? Either to fix the aspect ratio, or how to use the shape…
Cheers
Take a look at the second Merge Pictures example, its input "MergePicturesWithTemplates.docx" file has MergeFields with Shapes inside.
To place a Shape inside a MergeField, draw the shape, set it as "In Line with Text", and drag it inside the field.
Now that you have a shape as a placeholder for your image, you can add switches to MergeField in order to keep the aspect ratio of the merged picture:
\x - resize resulting picture horizontally, keep the template shape's height.
\y - resize resulting picture vertically, keep the template shape's width.
\x \y - resize resulting picture either horizontally or vertically.
To add a switch, press ALT + F9 in MS Word, that will reveal field's code and then write the switch within.

TableLayout heightPercentage: percentage of what?

I need to create a Container with a layout of two rows, the second one twice the height of the first, and put the container in the south position of a BorderLayout. I tried to do this using a TableLayout with two rows and one column, setting the height percentages to 33 and 67, respectively. However the TableLayout filled the entire screen, not just the "South" area. The javadocs indicate that the height percentage refers to the "parent", which I assumed would be the container with the TableLayout. But, apparently, the parent in question will be the display.
My next attempt was to create a TableLayout with three rows and one column, giving the lower content a vertical span of 2. But the bottom rows just disappeared.
Is there a solution I overlooked?
There are two separate stages in layout, requesting the preferred size and dealing with assigned size.
During the request stage we don't have the final size of everything so this is "guesstimated" (which amazingly my spell checker didn't flag?).
As we do the layout we already have an assigned size based on that preferred size and then the percentage is calculated based on that assigned size.
If you place a table layout container in the center of a border layout it will get all available space and so the preferred size aspect of the calculation phase will become meaningless and then percentage will be of the space allocated to the component which is "all available space". Naturally scrolling brings this into a completely different dimension.

Auto font size for TextBlock?

I have a XAML form with a TextBlock object that is set to a width of 500 and a height of 150 (for example).
I'd like to figure out a way to have the font size change automatcally depending on the text assigned to the object, such that it's as big as possible without overflowing the assigned bounds. Including word wrap as necessary and possible so that the text fills the available space both horizontally and vertically.
In other words, if the text is "Star" it would use a font size of 40 but for "superstar" it might get set to 18.45, using smaller text so the entire width of the object gets used. (The font's normal aspect ratio must be maintained.)
My experimenting with using a ViewBox hasn't provided the desired results as yet.

How do I calculate the required size for a CheckedListBox?

I have written some code to automatically scale a CheckedListBox to its contents using mListBox.ItemHeight and mListBox.CreateGraphics().MeasureString(...).
The output from the string measurements is a bit dubious but what really puzzles me is how much to add for borders and such.
I tried both SystemInformation.Border3DSize (= 2) as well as the difference between ClientSize and Size (= 4).
But taking mListBox.ItemHeight * mListBox.Items.Count + 4 for the height makes it one pixel too small and a scrollbar appears.
For the width it does not work at all because it does not take the size of the checkboxes into account for which I can't seem to find a source.
How should I determine the size of the control?
In cases like this, it is typically easier to set the ClientSize rather than the whole Size. One thing to note about ItemHeight is that it does not include the margins of the item. Using a CheckedListBox with default settings, I had an ItemHeight of 13. But the ItemRectangle property had a height of 15.
So here is what I did. I added 9 items to the CheckedListBox (the first Item was longer than the rest), keeping the default size of the control as set by the designer. Then in the constructor of the form, I set the ClientSize like so:
this.checkedListBox1.ClientSize = new Size(TextRenderer.MeasureText(checkedListBox1.Items[0].ToString(), checkedListBox1.Font).Width + 20, checkedListBox1.GetItemRectangle(0).Height * checkedListBox1.Items.Count);
Notice I used TextRenderer.MeasureText to measure the text. It will typically give you better values than Graphics.MeasureString. By default, TextRenderer included a bit of padding in it's measurement. I also included a 20 pixel padding to account for the checkbox. Anyway, with TextRenderer.MeasureText, and the 20 pixel padding for width, and ItemRectangle * Items.Count for the height, that gave me a CheckedListBox that was sized to its contents without ScrollBars.
EDIT: If item widths vary, it may complicate setting the width, as you'll want to set the width based on the longest item. In this case you'll need to measure each item and keep track of which one was the longest.
EDIT 2: Ok so I dug around in the CheckedListBox source code. They use a default size of 13 plus a 3 pixel padding for the width and height of the checkbox. But, if VisualStyles is enabled, they call CheckBoxRenderer.GetGlyphSize to get the size to use because it takes into account the DPI settings. Most machines are set at 96 DPI so that method will still return a size of (13,13). So when you're measuring the text of the item, you can also pass the Graphics object and a CheckBoxState enum to the CheckBoxRenderer.GetGlyphSize to get a size. I used System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal for the state, but I'm not sure that the state matters. I tried CheckBoxState.MixedDisabled as well and it returned the same size, (13,13).
So to summarize, you can use CheckBoxRenderer to get the size of the checkbox, but you will still probably need to use some padding. This reduces the need for hardcoding a magic number to account for the checkbox. Since the checkbox is drawn and isn't an actual control, its size can't be determined like sizes of controls can.
Here is a link to the source of CheckedListBox. It wouldn't hurt to look at it. Specifically, look at the protected override void OnDrawItem method.
CheckedListBox Source

How do I implement WPF layout if sizes of peer elements are not independent?

Imagine I have two WPF FrameworkElements that need to be laid out. One element contains text, and the other shows line numbers for the text.
The widths of these two elements are not independent. For example, if the text element gets narrower, then more lines may wrap, which increases the number of lines, which may cause the line number element to grow wider (e.g. if the number of lines goes from 99 to 100). But if the line number element grows wider, then there's less space for the text element, etc.
How do I implement layout in WPF if the sizes of my child elements need to be calculated in concert with one another? I am new to WPF layout, but it looks like a fundamental assumption of MeasureOverride is that an element's size can be calculated without regard to the sizes of peers.
Thanks for any help.
Sounds to me you need to implement the layout in the container. See http://www.wpftutorial.net/CustomLayoutPanel.html on how to implement your own layout panel. I think a Grid layout can do what you want. See http://www.wpftutorial.net/GridLayout.html

Resources