form中有一个panel,panel上有5个checkbox,我想要的效果是:用鼠标拖动一个范围,这个范围内的checkbox的checkbox.font.color:=clred;
就像在window的文件夹中用鼠标拖动一个范围,这个范围内的文件夹和文件就被选中一个道理。
就像在window的文件夹中用鼠标拖动一个范围,这个范围内的文件夹和文件就被选中一个道理。
解决方案 »
- windows server2003升2008 SocketConnection1无法连接
- 请教:用olectrl 装载word2007,如何隐藏菜单栏?
- 在listview组件中画线的问题,急
- 图像与数据库相关的问题
- 在类中创建对象的问题
- 添加了ACTIVEX控件的方法后,在哪给方法写代码?如我加了MOVEUP方法!
- 高分寻求图表控件及其源代码,分不够再加!!!!
- 请教一个发布包的问题,修改了D7源代码后要怎么重新编译系统包呢
- 看看吧,???!!!~~~
- 请问:如何使在DBGRID或STRINGGRID等表格控件的一个CELLS中能够显示或编辑多行文本?
- 请教delphi播放音乐的问题!
- Incompatible types: 'String' and 'Integer'
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
RadioButton1: TRadioButton;
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
fDrag: Boolean;
fRect: TRect;
implementation{$R *.dfm}procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
fDrag := True;
SetCapture(Handle);
fRect.Left := X;
fRect.Top := Y;
fRect.BottomRight := fRect.TopLeft;
Canvas.DrawFocusRect(fRect);
end;
end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
i: Integer;
begin
if fDrag then
begin
Canvas.DrawFocusRect(fRect);
fRect.Right := X;
fRect.Bottom := Y;
Canvas.DrawFocusRect(fRect);
for i := 0 to self.ControlCount - 1 do
begin
if self.Controls[i] is TCheckBox then
// if CheckBox本身的矩形范围 与 鼠标拖动范围重叠 then
(self.Controls[i] as TCheckBox).Font.Color := clRed;
end;
end;
end;procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if fDrag then
begin
ReleaseCapture;
fDrag := False;
Invalidate;
end;
end;end.
这里要写个判断,判断控件的位置是否和fRect重合
BOOL IntersectRect(
LPRECT lprcDst, // intersection buffer
CONST RECT *lprcSrc1, // first rectangle
CONST RECT *lprcSrc2 // second rectangle
);Return Values
If the rectangles intersect, the return value is nonzero.
If the rectangles do not intersect, the return value is zero.
我自己试过的(直接在Form而非Panel)是可以的,CheckBox字体都变红。
这句代码是有执行的,但就是不变红奇怪了。。
你是在哪里执行的代码?self是什么?
刚才那个不变红是我自己的问题。已解决了。。
现在是要解决 判断控件的位置是否和fRect重合的问题了。还有没有高手能赐教的?