vb.net, label or textbox right-aligned - vb.net

OK, here's a problem i have. Searching the net did not help much.
In VB.net, you can right-align the text on a label. The label however has automatic word-wrap capabilities so it seems impossible to display a text in the label (of constant size) and always view the last part of the text.
I'm placing a folder name in the label and i'm always interested in seeing the last part of the text. As is now, if the path name is too large, i keep seeing the i.e. "C:\Documents and Settings" part, which i don't care to see. In VB6 when you right-align the text in a label, it displays the last part and if the text doesn't fit, it just cuts the text at the beginning. In VB.NET if the text is too large to fit in the label, word-wrap kicks in so you end up seeing the first part of the text only.
When using a textbox, even if it's right-aligned, if the text doesn't fit it just shows as much as possible from the START of the text (instead of from the END since it's right-aligned.)
Is there a way to achieve a similar behavior in VB.NET as in VB6's label?

Related

Textbox formatting string spaces wrongly

I have been messing around with this and just can't figure it out, I have data which I'm retrieving and then basically I am outputting to a form for the user to read etc.
When I get the text/data and write it to the textbox though it formats very strange, not how it looks when written on the console or copy and pasted to notepad etc.
I'm adding the text to a stringbuilder using appendline, now in the picture below when I console.writeline the stringbuilder it comes out just as it should and written, this is the right hand side of the picture. But then when I add the stringbuilder to the textbox on my form it goes all wrongly spaced as seen on the left hand side of the picture
Why is this happening? Now when I say select all the wrongly looking spaced text from the textbox then copy and paste into the likes of notepad, it looks perfect and identical to the right hand side. So it seems to have all the spacing but some reason the textbox is showing the spaces very strange. All the black is just product names/codes so just blacked it out so please ignore.
Thanks!
You have to use a monospaced font for the TextBox, as the input seems to be formatted by spaces.
Examples of monospaced fonts are Consolas or Courier New as stated in comments.

How to detect visible text in a text field in a PDF?

When using PDFBox to populate a text field in a form in a PDF, it is possible that the text overflows the text field and is not visible when opening the PDF in a viewer.
Question: Is it possible to use PDFBox to detect how much text within a text field is visible?
At the risk of falling victim to an XY problem, here is the context in which this came up.
I have a PDF which is provided by the Danish government, and the software I am creating needs to be able to fill out this form programmatically. On pages 5 and 6 of this document, there is a large blank area that needs to be filled out. The way the PDF creators designed it, they just made two text fields (named Text57 and Text58), which a person directly filling out the form would manually need to jump between.
The problem is, I need to be able to populate these fields with text, and if the text is too large to fit in the first text field, then it needs to overflow into the second text field. However, I do not seem to have any way of actually detecting when the text overflows in the first text field.
One workaround which could be acceptable, would be if I could modify the document to remove the second text field, and just have the first text field span multiple pages, but while playing around in Acrobat, this does not seem to be possible.
The PDF in question can be found here: https://www.trafikstyrelsen.dk/~/media/Dokumenter/10%20Bolig/Bolig/Private%20lejeboliger/Lejekontrakt/typeformular-a.pdf
Here is a code snippet which populates the problematic field with 100 lines numbered from 1 to 100.
PDDocument document = PDDocument.load(new File("typeformular-a.pdf"));
PDField text57 = document.getDocumentCatalog().getAcroForm().getField("Text57");
text57.setValue(IntStream.range(1, 101).mapToObj(Integer::toString)
.collect(Collectors.joining(System.lineSeparator())));
document.save("typeformular-a.out.pdf");
After the code is run, we can see that the text gets cut off after line 44. Of course I cannot simply count lines in my text, because under normal circumstances the lines in the text will wrap, which would invalidate that approach.
Auxiliary question: Is there any other approach that could solve this original problem of splitting text across multiple pages?

SSRS textbox clipping when exporting to PDF

I was working with an SSRS report that uses multiple textboxes in a list control. I found that when I ran and exported my report to PDF (and printed/exported to .XPS), certain textboxes would just ever so slightly get clipped.
Note: when the report rendered in SSRS development env., every textbox looked fine and the text never got clipped. The issue just occurs when exporting, and on seemingly random textboxes (random to me).
I've tried adjusting the height and width properties of the textboxes, and the CanGrow property to true/false. Even making the text a different size (like 5 point) or even a different font made no difference. The amount of text that filled the field didn't matter. I made sure the margins on the page were sufficient. I also made sure there were no other report objects that were overlapping the offending textboxes. Neighboring textboxes that displayed fine were set to be perfectly aligned vertically with ones that had the text problems, and still no luck.
None of these options above worked. I have also seen a few questions on stackoverflow that are similar, but not exact.
How do I keep these textboxes from clipping the text when exporting to PDF?
Thank you.
Sample: textbox text is cut off very slightly on SSRS report exported to PDF for certain textboxes
I have solved my own issue after some tinkering, though perhaps its not the best solution out there but it works.
I hard coded a space character at the end of each textbox field's expression that had the clipping issue,
For example:
=First(Fields!zipCode.Value) + " "
The only minor draw back is that it shifts the alignment of the text left by one space. Hope this helps.
I played around with all sorts of options with indent, padding and even added a gutter column. This seemed to work for a while but when the problem raised its head again, I just changed my font.
I think there might be something up with "Calibri" and "Calibri Light" but "Candara" seems fine.
Bit frustrating this only shows up on server generated pdfs as it makes the feedback loop so much longer.

Access Report: Wrap Text Not Working

I have a report with unbound textbox's in them. I populate these fields onLoad.
The problem, though, is that the if the text is too long, it will not wrap. I have set Can Grow = Yes but this does not seem to work.
Is it due to the fact I am adding the string to the field OnLoad? If so, how can I overcome this and force the text to wrap? I would want the width to remain constant, but the height to grow.
Figured this out... I right clicked the text box and selected Size > To Fit...
I had the box big enough to accommodate a second line. It wouldn't ever word wrap until I made the change above. Can Grow and Can Shrink did nothing, but I left them selected.
I open report from code in design mode, make changes to control source of the text fields, save and close report and lastly open it in preview mode. The only way I get what I want.
I know this is an old post but I've been running into the same issue and haven't been able to figure out a solution until now.
One of the fields in print preview was getting cut off for me and despite my best efforts to make sure all the formatting settings were correct (i.e. Can Grow/Shrink: On) for both the detail section and the specific field. Again, this issue only happened in print preview, which meant the reports that were getting printed had the text cut off.
Solution:
I ended up realizing that all of the other text fields were set to Plain Text and the text field giving me the issue was set to Rich Text. I changed it to Plain Text and voila! It displayed everything without any issues.
My guess is that if you're having this issue, make sure all of the fields are set to the same property (Rich Text/Plain Text). Not sure why Access has trouble with this but I hope this solution helps someone else out.
The simple solution to this huge problem is listed below.
Convert the property of the textbox from plain text to rich text.
Set the text align property to distribute.
Enable can shrink and can grow property of the text box. (Yes)
Done.
After a lot trial-and-error, the solution seems to be that the text box that you want to scroll must have enough height to show two vertical lines. A textbox that is only one line high will not scroll. (You must also have Can Grow set to 'Yes' for both the textbox and the detail section.)
You also have to have the CAN GROW of the section that the text box is in set to YES as well as the text box.

Spanish characters in vb.net desktop application

I'm learning Spanish and wrote an application to display a form at random intervals at random places on the screen. Spanish words are taken from random positions in a text file. When the form appears, a Spanish word is presented with a definition below it. When I click anywhere on the form it goes away to appear again later. The form appears at any interval less than ten minutes, or whatever value I enter for that.
Spanish characters with accent marks do not display correctly. A label is being used to render. What is the best way to have it display properly. I haven't done localization or other languages in a desktop application, only web. I only want to change the one label if possible. Thanks
I found the answer at http://www.vbforums.com/showthread.php?655592-RESOLVED-Extended-ASCII-characters-in-Stream-I-O and used the following code:
Private Const ISO_8859_1 As Integer = 28591
Dim encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding(ISO_8859_1)
reader = New IO.StreamReader(file_name, encoding)
It was removing the high order bit when reading the file. Labels render everything in the extended ascii set without issue.