Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

visual basic msflexgrid 1

Status
Not open for further replies.

Normally

IS-IT--Management
May 13, 2008
22
BB
I have flexgrid in which i have 10 columns. I want each cell to hold i character (i need to change forecolor). I want to place letters H,E,L,L,O in grid so they appear as HELLO and not H E L L O . How can i do it?
 
with Fgrid

.additem "H" vbTab & "E" & vbTab & "L" & vbTab & "L" & vbTab & "O"


for i = 1 to 5
.colwidt(i) = 100 ' adjust
next

end with
 
hi Peter
colwidth is too small.I have to make it > 200 to see the letters in columns. Then when i make column > 200 there is too much space between columns. Any further suggestions?
 
set it to the textwidth of a W, which is one of the widest letters. or pick a smaller letter if that's too much.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
But if you set the columns to be the right width for the letters of HELLO what happens if the next row is IDIOT, since columns 1 and 3 will be wide enough for H and L, which will be too wide for I and I, thus giving something like I D I OT?

Or will there only be one row, and you are simply using a flexgrid to get differing colours for each letter? In which case, why not use something like the RichtextBox instead?
 
hi Strongm
Actually i the words would be in a variable .Even when i set column width to be that of each letter in the var i'm still getting H E L L O - it seems min width is 200. Let me say what i'm doing. I'm developing a word game which would keep score of words formed - like scrabble. eg
GAME 10
AR
ME
EM
REM 25
Board would be GAME
REM

I would want to A in AR, M in ME, E in EM to be a different color. Hence the flexgrid with say 11 columns where col 0 - 9 for letters & col 10 for score. Also i want to be able to scroll. Any suggestions
 
as StrongM suggests

Use RichText Box

Only other thing can suggest is
make some .jpg 's with the letters of the alphabet
and display as Picture boxes changing colour of background

 
So you are just using the flexgrid to achieve different colours for each letter. In which case I stick to my suggestion that you use an alternative control such as a RichTextBox. You'll not be able to achieve what you want - the elimination of clear gaps - with the Flexgrid control because each cell has some padding inserted that you cannot remove (i.e you cannot position a character right up against the lefthand border of the cell), so there will always be additional whitespace that you have no control over.
 
hi srtongm
Would i then use a multiline rtb? If so how would i get the scores align? I know i can lock rtb to prevent editing & change mousepointer but how do i add new line? Can you give sample code?
 
Code:
[blue]Option Explicit

Private Sub Command1_Click()
    RichTextBox1.Text = ""
    RichTextBox1.Parent.ScaleMode = vbPixels ' tabs get set later using units matching scale mode of RTBs parent
    AddaLine "HELLO", 25
    AddaLine "REM", 10
    AddaLine "TEKTIPS", 99
End Sub

Private Sub AddaLine(strText As String, score As Long)
    Dim lp As Long
    ' Example simply uses random colours
    For lp = 1 To Len(strText)
        RichTextBox1.SelColor = RGB(255 * Rnd, 255 * Rnd, 255 * Rnd)
        RichTextBox1.SelText = Mid$(strText, lp, 1)
    Next
    RichTextBox1.SelColor = vbBlack
    RichTextBox1.SelBold = True
    RichTextBox1.SelTabCount = 1
    RichTextBox1.SelTabs(0) = 100
    RichTextBox1.SelText = vbTab & score & vbCrLf
    RichTextBox1.SelBold = False
End Sub[/blue]
 

If you just want to display your words, why not just use an array of labels? This way you can control the color of the text (and/or the background, too). And you can align them any way you want.

Since you started with flexgrid which normally you can not edit anyway, I assume that's what you want.

To scroll – I would put the labels on a frame inside of another frame with the scroll bar on the side. You can make it as long as you want and scroll it.


Have fun.

---- Andy
 
Thanks strongm

That was very helpful. What other routines are there for rtb? ex, how to implement mousemove,delete a line,get line number ect.
 
hi strongm
How to scroll an array of rich text boxes -No multiline feature.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top