views:

62

answers:

3

Hello guys

Is there anyway to align the text in msflexgrid in vertical orientation like excel does?

thanks

alt text

A: 

Not if you are talking about vertical rotation of text.

You could convert your text into a rotated image and then load the image.

Further on this...

You can print rotated text to a picturebox control and then assign the picturebox to a cell.

This link shows a similar usage of the method but for a slightly different reason.

http://vb.mvps.org/articles/ap199907.pdf

Cidtek
Yes i mean vertically rotated text. I thought about that solution, but what about quick editing like excel does?Check the picture i attached
Smith
A: 

Nothing built-in, but here is a hack I used a few years back. You pass in a string to the function and it passes back a string with a carriage return and line feed after every character.

Private Function VerticalString(ByVal strInput As String) As String
   Dim strReturn As String
   Dim i As Integer

   For i = 1 To Len(strInput)
      strReturn = strReturn & Mid$(strInput, i, 1) & vbCrLf
   Next i

   If Len(strReturn) > 1 Then
      strReturn = Mid$(strReturn, 1, Len(strReturn) - 1)
   End If

   VerticalString = strReturn

End Function

Private Sub FillGrid()
    flexgrid1.TextMatrix(1, 0) = VerticalString("Kc Chiefs")
End Sub

vertical text

Beaner
A: 

There is a lot to rotating Fonts by 90 degrees. VB6 uses an OLE StdFont object part of the stdole2 type library.

You will have to convert the StdFont into a GDI font to be able to manipulated it.

Here is a very nice post (Text At Any Angle) with sample code to go on doing exactly that.

The sample is drawing on a form, but I would think you can get a handle to a MSFlexGrid and draw into that.

You can then control when and how the text is drawn. If you want to edit the vertical text at runtime, you can show a horizontal textbox over the cell instead while editing the text and then draw the new text when finished editing.

François
thanks very much for you answer, how do i turn the textbox horizontally?
Smith
I'm assuming you mean turn the textbox vertical? I think you have to draw both, the textbox as well as the text through the GDI yourself if you want that. The problem here is the difference between showing text static (drawing it onto a form on every paint event) and dynamic (having the text interact with it's environment). I think even excel, when showing text vertical, shows the text in a horizontal control while editing. I'm also not sure it is the most practical or user friendly way to edit text in a vertical position.
François