Flexgrid: A long word is not wrapping in MSFlexgrid
Hello, unfortunately the MSFlexgrid control doesn't wrap long words, as the following
code sample shows.
Code:
Code sample :
Private Sub Form_Activate()
DoEvents
MSFlexGrid1.Height = 1600
MSFlexGrid1.RowHeight(1) = 800
MSFlexGrid1.WordWrap = True
MSFlexGrid1.TextMatrix(1, 1) = "XaaaaaaaaaaaaaaaaaY"
End Sub
So I coded my own wordwrapper function. It needs a TextBox with the "multiline" property
set to "True" and it is using "SendMessage". The wordwrapper is working fine :
Code:
Function wordwrapper(s As String) As String
Const EM_GETLINECOUNT = &HBA
Const EM_LINEINDEX = &HBB
Dim NumOfLines As Long, y As Long, firstCharInThisLine As Long
Dim firstCharInThisLineOld As Long
Text1.Text = s
'getting the number of lines in Text1 :
NumOfLines = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0&, ByVal 0&)
For y = 1 To NumOfLines - 1
firstCharInThisLine = SendMessage(Text1.hwnd, EM_LINEINDEX, y, ByVal 0&)
wordwrapper = wordwrapper & Mid(Text1, firstCharInThisLineOld _
+ 1, firstCharInThisLine - firstCharInThisLineOld) & vbCrLf
firstCharInThisLineOld = firstCharInThisLine
Next
wordwrapper = wordwrapper & Mid(Text1, firstCharInThisLineOld + 1)
End Function
My problem:
In the thread http://www.vbforums.com/showthread.p...le-long-words) I used the "DrawText"
API to break a single long word like "XaaaaaaaaaaaaaaaaaY" (successfully!).
-My question: How can I write the "DrawText" output to the Flexgrid Cell(1,1) ?
-I want to do this with an API, and I don't want to use MSFlexGrid1.TextMatrix(1, 1) = "XaaaaaaaaaaaaaaaaaY".
The API Viewer is showing eleven different "TextOut" functions.
Last edited by vb.elmar; Jun 26th, 2016 at 09:30 AM.
Re: Flexgrid: A long word is not wrapping in MSFlexgrid
This is a longshot because you'd probably be using this control over the MSFlexGrid if you had the choice, but do you have the ComponentOne VSFlexGrid in your components list? If so, you can set the OwnerDraw property to FlexODComplete, and then draw anything you like in any cell using API calls.
Re: Flexgrid: A long word is not wrapping in MSFlexgrid
Few programs, if any, will "break a whole word into multiple word-chunks"
Pay
the
rap
ist
Is it "Pay therapist" or "Pay the rapist"?
This is why they invented "auto-fit" to boxes and columns, and it's called "Word wrap", not "Letter wrap", it wraps whole words. You want it to wrap letters, from words.
It will look horrible using it for anything that has actual volume to it. (Which is why programs don't do it.)
I see y
ou went
to the s
tore fo
r groce
ries.
Re: Flexgrid: A long word is not wrapping in MSFlexgrid
He probably means the "default-color of the inner GridLines"
(visible in the ScreenShots only at the small vertical line between the "Me | You" cells).
Re: Flexgrid: A long word is not wrapping in MSFlexgrid
Originally Posted by luca90
first image
Yes, it's not "bold" it's just "grey", not "black".
Thus, change the color of the grid to grey, and it won't look "bold". (Illusion, it's just black, not bold. The other is just grey, not thinner. Both are, as it was said, only 1 pixel wide. "Bold" = "Thicker", not "Darker".)
My other post shows the same exact results with the MSHFlexGrid control... I just changed the color to grey. (This is the MSH grid, in the picture.)
Default color is Black... (The blue selected one, I changed to grey)
Last edited by ISAWHIM; Mar 29th, 2023 at 08:41 AM.
Re: Flexgrid: A long word is not wrapping in MSFlexgrid
Originally Posted by ISAWHIM
Yes, it's not "bold" it's just "grey", not "black".
Thus, change the color of the grid to grey, and it won't look "bold". (Illusion, it's just black, not bold. The other is just grey, not thinner. Both are, as it was said, only 1 pixel wide. "Bold" = "Thicker", not "Darker".)
My other post shows the same exact results with the MSHFlexGrid control... I just changed the color to grey. (This is the MSH grid, in the picture.)
Default color is Black... (The blue selected one, I changed to grey)
Re: Flexgrid: A long word is not wrapping in MSFlexgrid
Originally Posted by ISAWHIM
Few programs, if any, will "break a whole word into multiple word-chunks"
Pay
the
rap
ist
Is it "Pay therapist" or "Pay the rapist"?
This is why they invented "auto-fit" to boxes and columns, and it's called "Word wrap", not "Letter wrap", it wraps whole words. You want it to wrap letters, from words.
It will look horrible using it for anything that has actual volume to it. (Which is why programs don't do it.)
I see y
ou went
to the s
tore fo
r groce
ries.
Just wanted to point out that there are programs that WILL do this. Desktop publishing programs that are fitting text to column widths will do this. They prefer to fiddle with the spacing between words, but if a word must be split up then there is a way to do that in written English: The hyphen.
Interestingly, this is akin to the line continuation character in VB, as it is a character that means 'this continues on the next line', though in VB, it is that the line of logic continues on the next line, while in written English it means that the word continues on the next line. Note that it solves the first example, because there is no ambiguity as to which parts of the word go together when you use a hyphen to connote word continuation.