把DBGrid的PopupMenu关联去掉,然后在OnMouseUp事件中自己弹出菜单: procedure TForm1.DBGrid1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var p: TPoint; begin if Button = mbRight then begin p := Point(DBGrid1.MouseCoord(X, Y).X, DBGrid1.MouseCoord(X, Y).Y); if (p.X > 0) and (p.Y > 0) then begin p := DBGrid1.ClientToScreen(Point(X, Y)); PopupMenu1.Popup(p.X, p.Y); end; end; end;
procedure TForm1.DBGrid1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if button=mbright then begin if (y<17) then dbgrid1.PopupMenu:=nil else dbgrid1.PopupMenu:=popupmenu1; end; end;
把dbgrid中的column所关联的菜单取消后,问题已经解决。 if (p.X > 0) and (p.Y > 0) then begin p := DBGrid1.ClientToScreen(Point(X, Y)); PopupMenu1.Popup(p.X, p.Y); sysu能解释一下这段代码吗?
procedure TForm1.DBGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var p: TPoint;
begin
if Button = mbRight then begin
p := Point(DBGrid1.MouseCoord(X, Y).X, DBGrid1.MouseCoord(X, Y).Y);
if (p.X > 0) and (p.Y > 0) then begin
p := DBGrid1.ClientToScreen(Point(X, Y));
PopupMenu1.Popup(p.X, p.Y);
end;
end;
end;
Shift: TShiftState; X, Y: Integer);
begin
if button=mbright then
begin
if (y<17) then
dbgrid1.PopupMenu:=nil
else
dbgrid1.PopupMenu:=popupmenu1;
end;
end;
if (p.X > 0) and (p.Y > 0) then begin
p := DBGrid1.ClientToScreen(Point(X, Y));
PopupMenu1.Popup(p.X, p.Y);
sysu能解释一下这段代码吗?