J
jbas
Unregistered / Unconfirmed
GUEST, unregistred user!
我试着画一个虚框在image上,但对form这个可用,
对image,如果不是.bmp就会把image上的图片清除,是.bmp就什么反映都没有。大侠们帮帮忙!
unit Unitdrawfocusrect;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, RxGIF, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
MyPoint:TPoint;
FDrawing:boolean;
MyDrawRect:TRect;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDrawing:=true;
MyDrawRect.Left:=X;
MyDrawRect.Top:=Y;
MyDrawRect.BottomRight:=MyDrawRect.TopLeft;
MyPoint:=point(X,Y);
drawfocusrect(image1.Picture.Bitmap.Canvas.Handle,MyDrawRect);
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDrawing:=false;
drawfocusrect(image1.Picture.Bitmap.Canvas.Handle,MyDrawRect);
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if FDrawing=true then
begin
drawfocusrect(image1.Picture.Bitmap.Canvas.Handle,MyDrawRect);
if X>MyPoint.X then
begin
MyDrawRect.Left:=MyPoint.X;
MyDrawRect.Right:=X;
end
else
begin
MyDrawRect.Left:=X;
MyDrawRect.Right:=MyPoint.X
end;
if Y>MyPoint.Y then
begin
MyDrawRect.Top:=MyPoint.Y;
MyDrawRect.Bottom:=Y;
end
else
begin
MyDrawRect.Top:=Y;
MyDrawRect.Bottom:=MyPoint.Y
end;
Drawfocusrect(image1.Picture.Bitmap.Canvas.Handle,MyDrawrect);
end;
end;
end.
对image,如果不是.bmp就会把image上的图片清除,是.bmp就什么反映都没有。大侠们帮帮忙!
unit Unitdrawfocusrect;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, RxGIF, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
MyPoint:TPoint;
FDrawing:boolean;
MyDrawRect:TRect;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDrawing:=true;
MyDrawRect.Left:=X;
MyDrawRect.Top:=Y;
MyDrawRect.BottomRight:=MyDrawRect.TopLeft;
MyPoint:=point(X,Y);
drawfocusrect(image1.Picture.Bitmap.Canvas.Handle,MyDrawRect);
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDrawing:=false;
drawfocusrect(image1.Picture.Bitmap.Canvas.Handle,MyDrawRect);
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if FDrawing=true then
begin
drawfocusrect(image1.Picture.Bitmap.Canvas.Handle,MyDrawRect);
if X>MyPoint.X then
begin
MyDrawRect.Left:=MyPoint.X;
MyDrawRect.Right:=X;
end
else
begin
MyDrawRect.Left:=X;
MyDrawRect.Right:=MyPoint.X
end;
if Y>MyPoint.Y then
begin
MyDrawRect.Top:=MyPoint.Y;
MyDrawRect.Bottom:=Y;
end
else
begin
MyDrawRect.Top:=Y;
MyDrawRect.Bottom:=MyPoint.Y
end;
Drawfocusrect(image1.Picture.Bitmap.Canvas.Handle,MyDrawrect);
end;
end;
end.