Re: How to simulate the double-click event?
- From: "Rick Rothstein" <rickNOSPAMnews@xxxxxxxxxxxxxxxxx>
- Date: Fri, 21 Apr 2006 12:32:25 -0400
Jeff, thanks for the input. I chose a rich text box because I have a
large list and I wanted the scroll bars. I had previously used a plain
text box, but I like the text colors I can get with RTB. The user will
not edit the text. The tool bar I see does not include a "Grid" so I
couldn't look at that. What would I have to do to add this?
You would do this to get to the "grid"... Click on Project on VB's MenuBar
and select Components from the item list that appears. Once the dialog box
appears, scroll down to Microsoft FlexGrid Control 6.0 and put a click the
CheckBox next to it to put a check mark in it. When you click OK, a new
control will be added to your Tool Palette (it is dark yellow). Double click
that icon to place it on your form. Here is an example that uses it (the
FlexGrid) as if it were a ListBox where only one item can be selected at a
time. (Don't be put off by the amount of code; most of it is in the
Form_Load event and simply sets display properties for the grid.) Clicking
either the right or left arrow will select the item; however, you can pop up
your TextBox in response to the right click by placing the appropriate code
in the section I indicated in the MouseDown event.
Private Sub Form_Load()
Dim Index As Long
Const VisibleRows As Long = 9
Const WidthOfGrid As Long = 3000
With MSFlexGrid1
.Font = "Arial"
.Font.Size = 10
.Cols = 1
.Rows = NumberOfLinesOfText
.FixedCols = 0
.FixedRows = 0
If NumberOfLinesOfText > VisibleRows Then
RowsToDisplay = VisibleRows
.ScrollBars = flexScrollBarVertical
Else
RowsToDisplay = NumberOfLinesOfText
End If
.Height = RowsToDisplay * (.RowHeight(0) + .GridLineWidth)
.Width = WidthOfGrid
.ColWidth(0) = .Width
.Appearance = flexFlat
.FocusRect = flexFocusNone
.BackColor = vbWhite
.ForeColor = vbBlack
.BackColorSel = vbBlack
.ForeColorSel = vbWhite
.ScrollTrack = True
' Color grid lines if shown
.GridColor = &HC0C0C0
' Hide the grid lines, remove this line to show them
.GridLines = flexGridNone
' Fill the grid with something to start with
For Index = 0 To .Rows - 1
.TextMatrix(Index, 0) = "Text for Line #" & CStr(Index)
.Row = Index
' Exaggerated example just to show items can be
' colored individually; colors will be alternated
' between red, blue and black
If Index Mod 3 = 0 Then
.CellForeColor = vbRed
ElseIf Index Mod 3 = 1 Then
.CellForeColor = vbBlue
End If
Next
' Just to make sure you can see the grid for this example
.Move 120, 120
End With
End Sub
Private Sub MSFlexGrid1_MouseDown(Button As Integer, _
Shift As Integer, x As Single, y As Single)
' Needed to stop contiguous row selections
With MSFlexGrid1
.Redraw = False
If Button = vbRightButton Then
.Row = .MouseRow
'
' You can show your TextBox here
'
End If
End With
End Sub
Private Sub MSFlexGrid1_MouseUp(Button As Integer, _
Shift As Integer, x As Single, y As Single)
With MSFlexGrid1
If .Rows - .TopRow < VisibleRows Then
.TopRow = .Rows - VisibleRows
End If
' Needed to stop contiguous row selections
.RowSel = MSFlexGrid1.Row
.Redraw = True
End With
End Sub
Private Sub MSFlexGrid1_Scroll()
With MSFlexGrid1
If .TopRow > NumberOfLinesOfText - RowsToDisplay Then
.TopRow = NumberOfLinesOfText - RowsToDisplay
End If
End With
End Sub
Rick
.
- Follow-Ups:
- Re: How to simulate the double-click event?
- From: Clark
- Re: How to simulate the double-click event?
- References:
- How to simulate the double-click event?
- From: Clark
- Re: How to simulate the double-click event?
- From: Jeff Johnson [MVP: VB]
- Re: How to simulate the double-click event?
- From: Clark
- How to simulate the double-click event?
- Prev by Date: Re: Getting the printer image
- Next by Date: Re: Starting PPT from VB6
- Previous by thread: Re: How to simulate the double-click event?
- Next by thread: Re: How to simulate the double-click event?
- Index(es):