vb.net I am trying to size a control (label, textbox, richtextbox) so that it is the smallest square that contains a given string - vb.net

I need to present arbitrary text, which might include line breaks, in a square control with word wrap such that the square is as small as possible but sufficiently large to display the text in its entirety.
This is the closest I've gotten so far:
Load the text into a temporary rich text box, Rich, with BorderStyle = none
I increment the value of size, width=height=size until Rich.ClientRectangle.Width = Rich.Width.
If I could now extract the visual lines one by one I would be done, as I could then save the original string with appropriate line breaks for later display.
Visual lines are not, of course, the same as Rich.Lines array.
Any ideas?
Thank you.

Related

How to increase the text field size within sanity studio?

How can I increase the height of the text input in sanity studio? when the user enters a lot of text, I would like it to go to the next line making it far easier to read.
I have tried adjusting the row property on the text type, but everything stays on the same line.

How do you detect if a specific string will either fit or take up a second line in a textbox in Crystal Reports/VB.NET/SQL?

So basically I have a textbox with a specific width and I need to know if the string I will put into it will either fit nicely in one line or take a second line. For example: I have
string v = "WERTYUIOSDFGHJKWERTYUISDFGHJKXCVBNSDFGHJ"
and a textbox that's 3000 in width.
At first I tried: if v.length = x then... where x is the length of the string that can fit into the textbox. But I soon found out that strings with mostly 'I' can fit more inside compared to a string of mostly 'M'. And that is where the problem lies. Is there a function that detects if the string is going to take/need a second line?
Another option is to create or use a 3rd-party Crystal Reports UFL (User Function Library). A list of 3rd-party UFLs is maintained by Ken Hamady here.
At least one of these UFLs provides functions that allow Crystal formulas to either:
a. specify as input the text, font name, font size, bold and italics status and get the required width (in pixels or twips), or
b. specify the available width for the text and get the maximum font size to fit, or the number of lines required for a given font size.
The advantage of using a UFL approach is that Crystal supports dynamic property expressions. That means that the result of the function call can dynamically control a property such as font size, height, position, etc.

Add text box at specific location in report base on value

I'm working on a cut list generator but I'm having difficulty on the final report. I'd like to display a rectangle that represents the factory length piece with lines indicating cut points. In each segment I'd like to have the length of the piece shown. Using Report.line I've created the rectangles needed but I'm not sure how to get text in each box. Here is a sample output so far As an example I want the three rectangles for Piece #1 to have 48" in them, probably all the way to the left. Any suggestions? I thought createReportControl might work but I'm not sure that is the correct approach. I'm also thinking about one text box with a monospace font so I can scale the input across the entire width. Any suggestions are appreciated.
Thanks,
Dave
I played around with the monospace font idea. It isn't as pretty as I would like but I'm getting closer.
The issue is that I cannot keep the text in the same spot in each box. There is one line lower on the page that pushes the number almost out the right side of the box.
Sample Output
This code is functional but I'm looking at the cosmetics. I'm inserting spaces between my values using the following function:
Private Function InsertSpaces(CutLen, PieceLen) As String
MaxChar = 50 ' 6 inch 14pt Courier text box
cutchar = Int(CutLen / PieceLen * MaxChar)
Cutcharcount = Len(Str(CutLen))
cutchar = cutchar - Cutcharcount + 1
For i = 1 To cutchar
InsertSpaces = InsertSpaces + " "
Next
End Function
I'm just trying to clean it up. CreateReportControl was giving me a error because I wasn't in design mode. I'm guessing that is because it ran as part of OnFormat of the Detail section.

How to make long text fit into a text_frame? Python-pptx

I'm working with python-ppt to create a portfolio of candidates in a Powerpoint presentation. There is one candidate per slide and each of them has provided information about themselves like name, contacts and a minibio (the problem I'm here to solve)
The text_frame, created with values of height and width, must fit the slide but must a contain all lenght of minibios, which is not happening.
In a long phase (>200 char, with font size 12) it exceeds the size of the text box and get "out" of the slide, so, in presentation mode or a PDF file, the "overrun" of text is lost
Is there any way to confine the text to the shape/size of the text_frame? (extra help if the solution wont change font size)
Just found one parameter that helped to find the answer
When creating a text_box object with slides.shapes.add_textbox() and adding a text_frame to it, the text_frame.word_wrap = True limits the text to be contained inside the dimentions of the text_box
The code shows it better
# creates text box with add_textbox(left, top, width, height)
txBox = slide.shapes.add_textbox(Cm(16),Cm(5),Cm(17),Cm(13))
tf = txBox.text_frame
tf.word_wrap = True
Before word_wrap parameter
After word_wrap parameter
The short answer is "No". PowerPoint is a page-layout environment, and much like the front page of a newspaper, text "story" content needs to be trimmed to fit the allotted space.
We're perhaps not used to this because word-processing, spreadsheet, and web-page content is "flowed" into a (practically) unlimited space, but the area of a PowerPoint slide is quite finite. Also, using it for large text blocks is somewhat of an off-label use. There is a certain amount of flexibility provided by reducing the font size, but not as much as one might expect. Even accommodating 20% additional text requires what appears as a pretty radical change in font size.
I've encountered this problem again and again, and the only solution I have ever seen work reliably is hand-curating the content to fit.
python-pptx has one experimental feature to address this but its operation has never been very satisfactory and it's tricky to get working. https://python-pptx.readthedocs.io/en/latest/api/text.html#pptx.text.text.TextFrame.fit_text
The business of fitting text is the role of a rendering engine, which python-pptx is not.

MS Word Ignores Content Control Inside a Rich Text Box

Is there a reason why my MS Word VBA macro is ignoring a dropdown list I placed inside a shape (a rich text box)? I've tried referring to it by tag, name, number, etc. I even had the macro tell me the count of content controls:
MsgBox(ActiveDocument.ContentControls.Count)
I get 0.
Nothing works. If I take it out of the shape, it works fine. MS Word gives me a count of 1 item. But for some reason MS Word won't acknowledge it inside the shape. Any help on how to do this?
Edited as my previous post was completely wrong.
Each textbox in the main text story is a Shape which you can access using an index number. A shape has various properties but text etc. is in its Textframe, if it has one. But in that case the Range you need is not called Range but TextRange. So, e.g. the first contentControl in Shape 2 is
ActiveDocument.Shapes(2).TextFrame.TextRange.ContentControls(1)
You will probably need to iterate through your shapes and you may need to verify that a given shape is a textbox and/or that it has a TextFrame.
If your text box is in another Story such as a header or footer, you will probably need to identify the relevant StoryRange.