如何在使用鼠標選擇單元格並單擊按鈕後在Delphi drawgrid單元格內繪製內容。按下按鈕後要繪製的單元格。如何使用按鈕單擊繪圖中的選定單元格
回答
將繪圖信息存儲在單獨的容器中,例如與網格中的單元格數量相同的項目數組,然後使用網格的OnDrawCell
事件根據需要使用當前存儲在容器中的信息繪製單元格。爲了更新繪圖,simpy根據需要更新容器的內容,然後用Invalidate()
網格觸發重繪,以便OnDrawCell
事件使用新信息。
更新:例如:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids;
type
CellInfo = record
BkColor: TColor;
end;
TForm1 = class(TForm)
DrawGrid1: TDrawGrid;
Button1: TButton;
procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
Cells: array of CellInfo;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
Vcl.ExtCtrls;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
R: TGridRect;
Row, Col: Integer;
begin
R := DrawGrid1.Selection;
for Row := R.Top to r.Bottom do
begin
for Col := R.Left to R.Right do
begin
Cells[(Row * DrawGrid1.ColCount) + Col].BkColor := clBlue;
end;
end;
DrawGrid1.Invalidate;
end;
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
CellIndex: Integer;
begin
CellIndex := (ARow * DrawGrid1.ColCount) + ACol;
if gdFixed in State then
begin
DrawGrid1.Canvas.Brush.Color := DrawGrid1.FixedColor;
end
else if (State * [gdSelected, gdHotTrack]) <> [] then
begin
DrawGrid1.Canvas.Brush.Color := clHighlight;
end else
begin
DrawGrid1.Canvas.Brush.Color := Cells[CellIndex].BkColor;
end;
DrawGrid1.Canvas.FillRect(Rect);
if gdFixed in State then
Frame3D(DrawGrid1.Canvas, Rect, clHighlight, clBtnShadow, 1);
if gdFocused in State then
DrawGrid1.Canvas.DrawFocusRect(Rect);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
begin
SetLength(Cells, DrawGrid1.RowCount * DrawGrid1.ColCount);
for I := Low(Cells) to High(Cells) do
begin
Cells[I].BkColor := DrawGrid1.Color;
end;
end;
end.
你是第一個發佈答案:-)嗯,這個容器應該最好作爲表單的索引屬性。因此,改變標誌的值將自動調用從設置者的無效 –
如果可能我可以有一些代碼 – furathamaKos
@furathamaKos:我更新了我的答案與一個例子。 –
- 1. 單擊tableviewcell上的按鈕單擊單元格不按鈕
- 2. tableview中的單選按鈕單元格
- 3. 如何從qtablewidget中檢測單元格中單擊的按鈕
- 4. 單選按鈕中的單選按鈕行格柵視圖
- 5. 如何在iOS中按鈕單擊時取消選擇所有單選按鈕uitableview單元格
- 6. 單擊單元格我想給一般單選按鈕
- 7. 如何使用按鈕單擊繪圖 - C++ Windows窗體
- 8. 如何更改表格單元格中的UIImageView圖像,單擊單元格上的按鈕?
- 9. 如何插入選定的單選按鈕值轉換成表格單元格
- 10. 如何跟蹤表格視圖單元格中按鈕的選定行?
- 11. 單擊按鈕時獲取表格視圖單元格索引
- 12. 如何在單擊該單元格中的按鈕時更改自定義單元格中的標籤文本
- 13. 在單擊定製單元格中的按鈕時獲取包裝單元
- 14. 單擊按鈕後,如何啓用/激活單選按鈕?
- 15. 單擊單元格contentview按鈕後如何訪問單元格信息?
- 16. 在TStringGrid中單元格中的按鈕上繪製圖像
- 17. Flash單選按鈕:如何獲取選定的單選按鈕?
- 18. 查找表格單元格中單擊按鈕的行索引
- 19. WPF DataGrid - 用鍵盤單擊單元格中的按鈕
- 20. 如何點擊按鈕或圖像,而不用Swift選擇整個單元格?
- 21. 單擊按鈕時隱藏UItableview單元格內的圖像
- 22. 如何禁用單選按鈕單擊另一個單選按鈕
- 23. iOS - 使用UITableView自定義單元格編輯按鈕點擊
- 24. 在單元格中的單擊按鈕上添加新的單元格行
- 25. 單擊單選按鈕時
- 26. 在按鈕上繪圖單擊 - Visual C++
- 27. 如何使用jquery在可點擊的表格單元格中切換「checked」單選按鈕?
- 28. 在單選按鈕單擊後,取消更改表格單元格的顏色
- 29. 如何在swift ios中點擊單元格中的按鈕?
- 30. 在表格視圖單元格中使用按鈕出列單元格
可以告訴你,你有這麼遠的任何代碼? –