こんにちわ。いつも参考にさせて貰っています。
OLEで行うと簡単に実現可能なのですが,Excelのブックを複数起動すると
以下の様な現象になるのでStringGridにて作成しているところです。
https://www.petitmonte.com/bbs/answers?question_id=4606
『コピー,貼り付け,切り取り,元に戻す』 の4つの機能はほぼ作成できたのですが,
Excelの様にコピー元を分かりやすくしたいので 波線?で囲んだ状態にしたいと思っています。
ただどのように実現すればいいのか分からない状態です。
(コピー元を塗りつぶす処理はできるのですが・・・)
方法をご存じの方がいれば教えて貰えると幸いです。
WindowsXP SP2
Delphi7 Enterprise
※追記
OnDrawCellイベント内で以下のようにすると大分近い物にはなりました。
CopyRect は コピー時の座標(TGridRect型)
//コピー元及び切り取り元を明示的にする
if (CopyRect.Left <= ACol) and (CopyRect.Right >= ACol) and
(CopyRect.Top <= ARow) and (CopyRect.Bottom >= ARow) then
begin
if gdFocused in State then
begin
StringGrid1.Canvas.DrawFocusRect(Rect);
end;
StringGrid1.Canvas.DrawFocusRect(Rect);
end;
ただ複数セル選択時には個々のセルに対してフォーカスが
当たる状態になっており若干見にくくなります。
複数セル選択時にもExcelの様に出来ないものでしょうか?
(今回飛び飛びの離れたセルは想定していません。連続したセルのみです。)
力不足の為,お知恵を貸して頂ければと思います。
よろしくお願いします。
>波線?で囲んだ状態
OnDrawCellイベント内で LineToで線を引くのはどうですか?
LineToを使用してなんとか出来ました。
ありがとうございました。
CopyRect は コピー時の座標(TGridRect型)
OnDrawcellイベント内
//コピー元及び切り取り元を明示的にする
if (CopyRect.Left <= ACol) and (CopyRect.Right >= ACol) and
(CopyRect.Top <= ARow) and (CopyRect.Bottom >= ARow) then
begin
//ペン変更
StringGrid1.Canvas.Pen.Style := psDot;
StringGrid1.Canvas.Pen.Color := clBlack;
//左
if CopyRect.Left = ACol then
begin
StringGrid1.Canvas.PenPos := Point(Rect.Left, Rect.Top);
StringGrid1.Canvas.LineTo(Rect.Left, Rect.Bottom - 1);
end;
//右
if CopyRect.Right = ACol then
begin
StringGrid1.Canvas.PenPos := Point(Rect.Right - 1, Rect.Top);
StringGrid1.Canvas.LineTo(Rect.Right - 1, Rect.Bottom - 1);
end;
//上
if CopyRect.Top = ARow then
begin
StringGrid1.Canvas.PenPos := Point(Rect.Left, Rect.Top);
StringGrid1.Canvas.LineTo(Rect.Right - 1, Rect.Top);
end;
//下
if CopyRect.Bottom = ARow then
begin
StringGrid1.Canvas.PenPos := Point(Rect.Left, Rect.Bottom - 1);
StringGrid1.Canvas.LineTo(Rect.Right - 1, Rect.Bottom - 1);
end;
//ペン元に戻す
StringGrid1.Canvas.Pen.Style := psSolid;
end;
ツイート | ![]() |