I'm encountering an issue when using a Label. It has Autosize property set to False, AutoEllipsis property set to True and TextAlign set to MiddleLeft. The Label has also a fixed size of (296, 25).
The problem:
As soon as the text reaches boundary limits it displays "..." but also moves text to the upper corner. I'm assuming this is because label size is greater than the text font, therefore it tries to fit more text within the control. I don't want this behavior. I want text to be single line only and when ellipsis is displayed I want it to remain text position set in properties.
Any ideas how to fix this bug?
You can measure your Label's text Width first and then give some top Padding if Label's Width is smaller. In other words, when Label's AutoEllipsis "happens".
Dim _TextSize As System.Drawing.Size = TextRenderer.MeasureText(YourLabel.Text, YourLabel.Font)
If _TextSize.Width > YourLabel.Width Then
YourLabel.Padding = New Padding(0, 6, 0, 0)
Else
YourLabel.Padding = New Padding(0, 0, 0, 0)
End If
Related
Trying to set the height along with setting the rotation on a Paragraph object results in the following error:
ERROR c.i.layout.renderer.BlockRenderer - Rotation was not correctly processed for ParagraphRenderer
Also, the height is sent to infinity resulting in an apparently empty page which I'm not sure if it's the expected behavior or not.
If I don't set the height, the text shows up rotated (which is what I want). But my task is to place the text at certain coordinates with certain dimensions and rotation. The placement is fine, but not being able to set the height results in assigning the rotation points to the wrong values and in turn displacing the final position of the text.
Paragraph paragraph = new Paragraph(text);
paragraph.setHeight(height);
paragraph.setMargins(0, 0, 0, 0);
paragraph.setProperty(ROTATION_POINT_X, x);
paragraph.setProperty(ROTATION_POINT_Y, y);
paragraph.setProperty(ROTATION_ANGLE, asFloat(toRadians(rotation))));
document.add(paragraph);
Setting the margins to 0 doesn't seem to have any influence either. The text looks to keep some sort of margin anyway.
So is there a way to control what the dimensions of the object displayed are? I could also settle for a way to make the rotation pivot from the center of the object.
You should set both width and height at the same time for rotated objects.
Here is an example code:
Paragraph paragraph = new Paragraph("Hello world");
paragraph.setWidth(200);
paragraph.setHeight(20);
paragraph.setBackgroundColor(ColorConstants.RED);
paragraph.setMargins(0, 0, 0, 100);
paragraph.setProperty(ROTATION_POINT_X, paragraph.getWidth().getValue() / 2);
paragraph.setProperty(ROTATION_POINT_Y, paragraph.getHeight().getValue() / 2);
paragraph.setRotationAngle(Math.PI / 180 * 45);
document.add(paragraph);
Visual result:
I'm trying to set my text which is inside a canvas to get vertically aligned with VerticalAlignment.BOTTOM property value, but whatever I put doesn't change the visual result.
retangulo = New iText.Kernel.Geom.Rectangle(122, AlturaPag - 208, 235, 27)
PdfCanvas = New iText.Kernel.Pdf.Canvas.PdfCanvas(page).SetLineWidth(1).Rectangle(retangulo).Stroke()
canvas = New iText.Layout.Canvas(PdfCanvas, retangulo)
texto = (New iText.Layout.Element.Text(Npagador).SetFontSize(11).SetBold)
' VerticalAlingment = BOTTOM \/
paragrafo = (New iText.Layout.Element.Paragraph().Add(texto).SetTextAlignment(TextAlignment.LEFT).SetVerticalAlignment(VerticalAlignment.BOTTOM))
canvas.Add(paragrafo)
You are trying to align the contents of the paragraph to the bottom of the paragraph itself, and the paragraph when laying itself out simply uses the minimal necessary height, so whatever alignment (bottom or top) you set, the result it just the same simply because paragraph packs itself to the minimal height.
To make sure setVerticalAlignment has an effect, you need to give the paragraph more vertical space by setting its height. Here is an example where I set paragraph height to match the height of the canvas you add it to, since it's the only element in the canvas. I also set the margins of the paragraph to zero so that you don't get additional spacing around the text.
The code is in Java but you will be able to convert it back to VB.NET as easily as I converted your code to Java:
Paragraph p = new Paragraph().add("Test").setTextAlignment(TextAlignment.LEFT)
.setVerticalAlignment(VerticalAlignment.BOTTOM).setHeight(retangulo.getHeight());
p.setMargin(0);
I already saw this question but it doesn’t help me.
The problem is that I can write the text to the PDF file, but if I do that with a new gfx.DrawString it put the second text on the first...
like this....
Here is my code I used to set a new line:
gfx.DrawString(lbname.Text + " " + lbnamei.Text, font, XBrushes.Black, new XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
gfx.DrawString(lbvorname.Text + " " + lbvornamei.Text, font, XBrushes.Black, new XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
I think it has something to do with the numbers in the first argument (new XRect(0, 0,) but it is unclear how to set them.
I can't remember which parameter does which, but this will help you discover for yourself:
Set one of the numbers to 20 on one of the pieces of text; observe the effect. Then change it back and change a different number; observe the effect.
An XRect has the four parameters x, y, width, height. x is the position from the left, y is the position from the top.
Width and height have no effect as long as XStringFormats.TopLeft is used. Therefore it is enough with the code shown above to increment y to draw text in a new line.
Width must be set to have text that is right-aligned or horizontally centered.
Height must be set to have text that is bottom-aligned or vertically centered.
I have a Form with a Panel. In this Panel, I want to use the vertical scrollbar when I needed.
How do I do this? I've tried setting autoscroll true and set a min scroll height, but the scrollbar never appears.
I've also tried this:
my_panel.ScrollBars = ScrollBars.Vertical
but then I get the error that scrollbar is not a member of my_panel?
Thanks.
Autoscroll property is actually enough to achieve your need. Basically a panel with autoscroll property true will display the scroll bar only when the contents/components inside that panel exceeds over its bound. In other words, Scroll bar appears with controls which have autoscroll property set to true when the particular control's contents are larger than its visible area. I think your panel is having some minimum amount of contents/controls which fits inside that panel's bound.
I know You asked this question more then year ago, but... ;)
Recently, I had same problem (label inside panel, and I need only vertical scrollbar).
If You want only vertical scrollbar of panel with label inside, use code bellow :
Dim pnl As New Panel
pnl.Size = New Size(300, 200)
pnl.AutoSize = True
Dim lbl As New Label
lbl.Location = New Point(0, 0)
lbl.AutoSize = True
lbl.MaximumSize = New Size(pnl.Width - 18, 0)
'18 is approx. width of scroller, and height must be zero.
'even if Label is set to AutoSize, MaximumSize will not allow him to
'expand more then set width.
'Height of zero px will allow Label to expand as much as he need
pnl.Controls.Add(lbl)
Me.Controls.Add(pnl)
I hope this code help You.
btw. sorry for my weak English, I hope You will understand ;) :)
I'm using similar kind of functions to get some property attributes like Filename, bit depth, dimensions, size etc by using some vba code. The last line of that function would be something like the following:
PicSize = CreateObject("Shell.Application").Namespace(vPth2).Parsename(sPic2).ExtendedProperty("size")
Now, I want to get the height and width of that image file. I've put height and width in the ExtendedProperty attribute value but it's not giving me the height and width of that file.
Note that, in the property dialog box of that image file, in the summary tab, it is showing Bit depth but putting this did not work. Then I put bitdepth and it worked successfully. The names are not case sensitive.
Okay! Now all I want to get the height and width of that selected image file. How can I do that? I mean what to put inside ExtendedProperty() to get height and width.
An early reply with solution would be highly appreciated.
Can't help with why Height and Width don't work, but Dimensions seems to work, returns a string like ?493 x 376?
I suggest the work around method
replace size in your code
PicSize=CreateObject("Shell.Application").Namespace(vPth2).Parsename(sPic2).ExtendedProperty("size")
to Dimensions
you will get something like ?493 x 376?
now declare
a string t = "?493 x 376?"
'search the index of "x"
search_x = InStr(t, "x")
'we would got width and height by
width = Mid(t, 2, search_x - 2)
height = Mid(t, search_x + 2, Len(t) - 8)
It is unknow why but I found that start at "2" in width and "-8" in height like that would give a number