如何在运行时的Form上画出如设计时期的选择多个控件的虚框
2007-03-13 10:55
423 查看
实现方法,就是使用TShape控件。实现代码如下:
unit UnitMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StretchHandle, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Memo1: TMemo;
Shape1: TShape;
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;
pStart : TPoint;
implementation
{$R *.dfm}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
pStart.X := X;
pStart.Y := Y;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Shift = [ssLeft] then
begin
Shape1.Visible := True;
Shape1.Left := pStart.X;
Shape1.Top := pStart.Y;
Shape1.Height := Y - pStart.Y;
Shape1.Width := X - pStart.X;
end;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Shape1.Visible := False;
end;
end.
unit UnitMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StretchHandle, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Memo1: TMemo;
Shape1: TShape;
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;
pStart : TPoint;
implementation
{$R *.dfm}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
pStart.X := X;
pStart.Y := Y;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Shift = [ssLeft] then
begin
Shape1.Visible := True;
Shape1.Left := pStart.X;
Shape1.Top := pStart.Y;
Shape1.Height := Y - pStart.Y;
Shape1.Width := X - pStart.X;
end;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Shape1.Visible := False;
end;
end.
相关文章推荐
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- Jquery如何序列化form表单数据为JSON对象 C# ADO.NET中设置Like模糊查询的参数 从客户端出现小于等于公式符号引发检测到有潜在危险的Request.Form 值 jquery调用iframe里面的方法 Js根据Ip地址自动判断是哪个城市 【我们一起写框架】MVVM的WPF框架(三)—数据控件 设计模式之简单工厂模式(C#语言描述)
- 界面控件-如何选择适合自己的界面控件
- 如何设计一个 iOS 控件?(iOS 控件完全解析)
- 如何设计一个 iOS 控件?(iOS 控件完全解析)
- 写Form设计器尝试(四) 修改窗体上的控件属性
- flex自定义组件如何在设计时显示预期结果/已添加控件
- 设计模式之How to Select a Design Pattern 如何选择设计模式
- 牛腩购物9 用户表设计/动软生成器/金钱字段decimal(18, 2)/ 注册的时候的前台js判断/后台代码判断/正则表达式软件/RegexBuddy/设置数据库字段的唯一性约束/如何获取控件在前台html的id值/如何将C#的后台正则换成js的正则
- 希望大牛讨论 树状数据如何选择数据库和设计存储格式
- 在.NET 应用程序设计中如何选择Class, Abstract Class and Interface
- 如何设计一个 iOS 控件?(iOS 控件完全解析)
- 快速切换Python运行版本,如何选择Python版本
- 一个XAP中有多个Silverlight控件时如何选择调用
- CUDA程序在运行的时候如何选择可用的计算设备
- ORACLE-在设计数据库时如何选择正确的数据类型
- ASP.NET中如何让DropDownList控件既能做选择又能做输入用?
- c#如何在多线程中访问Form中控件的多种解决方案(收集)
- drupal_build_form 大致是如何运行的呢 ?