掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
imageのハンドル取得について (ID:11822)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
例をあげます。新規で試してください。Form1 に Image1: TImage; Image2: TImage; PaintBox1: TPaintBox; ApplicationEvents1: TApplicationEvents; をデフォルトのサイズでおいてください。そして procedure TForm1.FormCreate(Sender: TObject); begin with Image1 do begin Picture.Bitmap.Width := Width; Picture.Bitmap.Height := Height; Picture.Bitmap.Canvas.Brush.Color := clLime; Picture.Bitmap.Canvas.FillRect(ClientRect); end; with Image2 do begin Picture.Bitmap.Width := Width; Picture.Bitmap.Height := Height; Picture.Bitmap.Canvas.Brush.Color := clAqua; Picture.Bitmap.Canvas.FillRect(ClientRect); end; end; procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); var ctrl:TControl; begin if (Msg.hwnd = Handle) and (Msg.message = WM_LBUTTONDOWN) then begin ctrl := ControlAtPos(Point(LOWORD(Msg.lParam),HIWORD(Msg.lParam)),true,false); if ctrl is TImage then PaintBox1.Canvas.Draw(0,0,TImage(ctrl).Picture.Graphic) else PaintBox1.Refresh; end; end; とします。実行して、Image1 または Image2 のうえでクリックすると PaintBox1 にその色が反映されます。Form1を直接クリックすると 色が消えます。 TImage(ctrl).Picture.Graphic に注目してください。キャストの効用です。
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.