$INCLUDE "RapidQ.inc"
DEFINT RowCount=7
DEFINT ColCount=5
DEFINT DefaultColWidth=64
DEFINT DefaultRowHeight=24
DEFINT GridLineWidth=1
DEFINT GridLineColor=cldgreen
DEFINT GridWidth=GridLineWidth*(ColCount+1)+DefaultColWidth*ColCount
DEFINT GridHeight =GridLineWidth*(RowCount+1)+DefaultRowHeight*RowCount
DEFINT GridColor=&HBAFCE7
DEFINT cellAlignment=taCenter
DEFINT SelectedBGColor=clyellow
DEFINT SelCol,SelRow
DEFINT MergeStartCol=1
DEFINT MergeStartRow=1
DEFINT MergeCountCol=3
DEFINT MergeCountRow=3
DECLARE SUB SelectCell ( Sender AS QLABEL)
DECLARE SUB CellOnMouseDown (Button%, X%, Y%, Shift%, Sender AS QLABEL)
DECLARE SUB CellOnMouseUp (Button%, X%, Y%, Shift%,Sender AS QLABEL)
CREATE Form AS QFORM
CAPTION = "LabelGrid"
Width = 420
Height = 340
FormStyle = fsStayOnTop
Center
CREATE PanelGrid AS QPANEL
Left =2
Top = 2
Width=GridWidth
Height=GridHeight
CAPTION = "Panel1"
TabOrder = 8
COLOR=GridLineColor
BevelOuter =bvnone
BevelInner=bvnone
END CREATE
END CREATE
DIM Labels(RowCount,ColCount) AS QLABEL
k=0
FOR i=0 TO RowCount-1
FOR j=0 TO ColCount-1
Labels(i,j).PARENT=PanelGrid
Labels(i,j).tag=-k
Labels(i,j).Autosize=0
Labels(i,j).Alignment=cellAlignment
Labels(i,j).left=GridLineWidth*(j+1)+DefaultColWidth*j
Labels(i,j).top=GridLineWidth*(i+1)+DefaultRowHeight*i
Labels(i,j).CAPTION=STR$(Labels(i,j).top)
Labels(i,j).OnClick=SelectCell
Labels(i,j).COLOR=GridColor
Labels(i,j).Height=DefaultRowHeight
Labels(i,j).Width=DefaultColWidth
IF i>=MergeStartRow AND i<MergeStartRow+MergeCountRow AND j>=MergeStartCol AND j<MergeStartCol+MergeCountCol THEN
Labels(i,j).CAPTION="Merged"
Labels(i,j).visible =0
Labels(i,j).COLOR=clLBlue
END IF
IF i=MergeStartRow AND j=MergeStartRow THEN
Labels(i,j).Height=GridLineWidth*(MergeCountRow-1)+DefaultRowHeight*MergeCountRow
Labels(i,j).Width=GridLineWidth*(MergeCountCol-1)+DefaultColWidth*MergeCountCol
Labels(i,j).COLOR=clred
Labels(i,j).visible =1
END IF
INC k
NEXT j
NEXT i
Form.SHOWMODAL
SUB CellOnMouseDown (Button%, X%, Y%, Shift%,Sender AS QLABEL)
Sender.CAPTION=STR$(X%)+"\"+STR$(Y%)
END SUB
SUB CellOnMouseUp (Button%, X%, Y%, Shift%,Sender AS QLABEL)
END SUB
SUB SelectCell ( Sender AS QLABEL)
Labels(SelRow,SelCol).COLOR=GridColor
FOR i=0 TO RowCount-1
FOR j=0 TO ColCount-1
IF Sender.tag=Labels(i,j).tag THEN
SelCol=j
SelRow=i
ELSE
END IF
NEXT j
NEXT i
Sender.COLOR=SelectedBGColor
END SUB
|