こんにちは
StringGridで特定のセルにMaskEditなどのPasswordChar
のような機能を実現する方法を教えてください。
やっぱりカスタムコンポーネントを自作しないと
だめですかね?
よろしくお願いします。
入力丸見えでいいのなら・・・
procedure TForm1.StrGridExt1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
drawText: String;
begin
drawText := StrGridExt1.Cells[ACol, ARow];
if ACol = 2 then begin
drawText := StringOfChar('*', Length(WideString(drawText)));
end;
StrGridExt1.canvas.TextRect(Rect, Rect.Left +1, Rect.Top + 1,drawText);
end;
さらにおすすめできない方法を使って・・・
type
TMyGrid =class(TStringGrid)
end;
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
if TMyGrid(StringGrid1).InplaceEditor <> nil then begin
if ACol = 2 then begin
SendMessage(TMyGrid(StringGrid1).InplaceEditor.Handle, EM_SETPASSWORDCHAR, $2A{'*'}, 0);
end
else begin
SendMessage(TMyGrid(StringGrid1).InplaceEditor.Handle, EM_SETPASSWORDCHAR, 0, 0);
end;
TMyGrid(StringGrid1).InplaceEditor.SetTextBuf(PChar(TMyGrid(StringGrid1).InplaceEditor.Text));
end;
end;
既知の問題点
・普通の StringGrid を TMyGrid としてアクセスしており、「Delphi様の実装に依存するため、
いずれつかえなくなるかもしれない」・・・と、紹介されていることが多い。
・最初に入力するセルが、パスワード表示したいセルの場合見えてしまう。
>StringGridで特定のセルにMaskEditなどのPasswordChar
>のような機能を実現する方法を教えてください。
私なら・・・・
TMaskEditを特定のCellを選択したときにそのCell内に表示させます。
値は、別のWidthを-1にしたCellに保持させておきます。
通常はDrawCellで(ofZさんの参照)で、保持した値を元に描画させます。
するとあたかも・・・・
ってのは駄目ですか?
ofZさん、Syakeさん解答ありがとうございます。
本来StringGridはデータを表示するためのものですから
PasswordCharみたいな機能は本来矛盾してるんですよね。
今ごろ気づきました。
ofZの方法とSyakeさんの方法で実現したいとおもます。
ツイート | ![]() |