有关StringGrid的问题,望高手帮忙解答
void __fastcall TFrmPhaseControl::Button4Click(TObject *Sender){ ShowMessage("点到我了");}void __fastcall TFrmPhaseControl::StringGrid1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y){ int XCol,XRow; StringGrid1->MouseToCell(X,Y,XCol,XRow); if(XRow) { Button4->Parent=StringGrid1; Button4->Left=StringGrid1->CellRect(5,XRow).Left; Button4->Top=StringGrid1->CellRect(5,XRow).Top; Button4->Width=StringGrid1->ColWidths[5]; Button4->Height=StringGrid1->RowHeights[1]; Button4->Visible=true; Button4->OnClick=Button4Click; }}
button4设置bring to frontvoid __fastcall TForm1::StringGrid1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y){ int XCol,XRow; StringGrid1->MouseToCell(X,Y,XCol,XRow); if(XRow) { Button4->Left =StringGrid1->Left; Button4->Top=StringGrid1->Top; Button4->Width=StringGrid1->ColWidths[5]; Button4->Height=StringGrid1->RowHeights[1]; }}
[解决办法]
如果parent不是stringgrid
left和top不能按照mousemove里的x y 来计算了
Button4->Left=StringGrid1->CellRect(5,XRow).Left + StringGrid1->Left + 2;
Button4->Top=StringGrid1->CellRect(5,XRow).Top + StringGrid1->Top + 2;