您的位置:首页 > 移动开发

关于 TApplication 详解 五 ---- Tscreen

2010-11-29 16:55 155 查看
五、Tscreen

Tobject—> TPersistent—> Tcomponent

Tscreen的属性: 从TComponent继承来的:
In Tscreen DestroyComponents
ActiveControl FindComponent
ActiveCustomForm FreeNotification
ActiveForm FreeOnRelease
Cursor GetParentComponent
Cursors HasParent
CustomFormCount InsertComponent
CustomForms RemoveComponent
DataModuleCount SafeCallExecption
DataModeles 从TPersistent继承来的:
DefaultIme Assign
DefaultKbLayout GetNamePath
Fonts 从TObject继承来的:
FormCount ClassInfo
Forms ClassName
Height ClassNameIs
IconFont ClassParent
Imes ClassType
PixelsPerInch CleanupInstance
Width DefaultHandler
从Tcomponent继承来的: Dispatch
ComObject FieldAddress
ComponentCount Free
ComponentIndex FreeInstance
Components GetInterface
ComponentState GetInterfaceEntry
ComponentStyle GetInterfaceTable
DesignInfo InheritsFrom
Name InitInstance
Owner InstanceSize
Tag MethodAddress
VCLComObject MethodName
NewInstance
TScreen的方法 TScreen的事件:
In TScreen In TScreen
Create OnActiveControlChange
Destroy OnActiveFormChange

ActiveControl属性
对应对象:TScreen
声明:property ActiveControl :TWinControl;
功能:ActiveControl属性用来确定有焦点的控件。
在任何时候,整个屏幕上只有一个控件有焦点。如果控件在应用程序的外面,则用户不能访问它。一般ActiveControl被限制在应用程序的内部。

例子:
//Create a form with many controls,change the Interval property
//of the Timer to 500-every time a control is selected,the Form
//Caption changes to indicate which control has the foucus
procedure TForml.TimerlTimer(Sender:TObject);
begin
Form1.Caption := Screen.ActiveControl.Name;
end;

ActiveForm属性
对应对象:TScreen
声明:property ActiveForm :TForm;
功能:ActiveForm属性用来确定被激活的窗体是哪一个窗体。这个属性是只读型的。它指出具有焦点的窗体。

例子:
//Create a program with two forms-Show Form2 by
//clicking a button on the first form. This method will
//put the name of the active form on Form2’s caption
procedure TForm2.Timer1Timer(Sender : TObject);
begin
Form2.Caption := Screen.ActiveForm.Name;
end;

Cursor属性
对应对象:TScreen
声明: property Cursor:TCursor;
功能:Cursor属性用来确定光标的形状。
改变Cursor属性的值将对应地改变应用程序中用户区域的光标形状。
以下说明使用的TCursor类型时的可能值:

类型常数 值 功 能
crDefautl 0 依据ActiveControl。
crNone -1 无光标。
crArrow -2 标准光标。
crCross -3 十字光标。
crIBeam -4 I形光标。
crSize -5 十字箭头光标。
crSizeNESW -6 右斜方箭头光标。
crSizeNS -7 上下方箭头光标。
crSizeNWSE -8 左斜方箭头光标。
crSizeWE -9 左右箭头光标。
crUpArrow -10 向上箭头光标。
crHourGlass -11 等待光标。
crDrag -12 箭头加文本光标。
crNoDrop -13
crHSPlit -14 左右移动表格线光标。
crVSplit -15 上下移动表格线光标。
crMultiDrag -16 箭头加多文本光标。
crSQLWait -17 SQL加等待光标。
crNo -18
crAppStart -19 等待加箭头光标。
crHelp -20 箭头加问号光标。
crHandPoint -21 手光标。

例子:
procedure TForm1.FormCreate(Sender : TObject);
begin
Screen.Cursor := crUpArrow;
end;

Cursors属性
对应对象:TScreen
声明:property Cursors [Index:Integer] : HCursor;
功能:Cursors属性是用户可以使用的光标数组。
Cursors属性允许用户在应用程序中加载自定义的光标,全局光标的预定义集由TCursor来定义。前面介绍的Cursor属性中说明了TCursor类的光标元素。如果用户希望创建自己的光标,可以使用Delphi的图形编辑器来绘制光标,并且在源代码中说明一个常量来表示光标在Cursors数组中的位置,使用系统的API函数比LoadCursor以便使这个光标成为程序共享的资源。例如,设想一个用户定制的光标已经被加载到应用程序的资源中去,并且命名为NewCursor。以下的代码使这个光标在应用程序中是有效的,通过光标常数crMyCursor,并设置它是全局的。

例子:
implementation
{$R *.DFM}
const
crMyCursor = 5;
procedure TForm1.FormCreate(Sender : TObject);
begin
Screen.Cursors[crMyCursor] := LoadCursor(HInstance, ‘NewCursor’);
Cursor := crMyCursor;
end;

CustomFormCount属性
对应对象:TScreen
声明:property CustomFormCount : Integer;
功能:CustomFormCount说明了在屏幕上所显示的窗体号或属性页。

CustomForms属性
对应对象:TScreen
声明:property CustomForms [Index :Integer]:TCustomForm;
功能:CustomForms是一个所有的属性页和窗体的例表,它们是在当前的屏幕上显示。

DataModuleCount属性
对应对象:TScreen
声明:property DataModuleCount:Integer;
功能:DataModuleCount属性说明了在当前的应用程序中例示的数据模块的号。

DataModules属性
对应对象:TScreen
声明:property DataModules [Index:Integer]:TDataModule;
功能:DataModules是在当前应用程序中例示的所有数据模块的例表数组。

DefaultIme属性
对应对象:TScreen
声明:property DefaultIme:string;
功能:DefaultIme属性说明了输入方法编辑器的名,输入方法编辑器在TScreen对象被创建时被激活。

DefauItKbLayout属性
对应对象:TScreen
声明:property DefaultKbLayout:HKL;
功能:DefauItKbLayout属性是当应用程序开始运行时被激活的键盘版面所对应的窗口句柄。

Fonts属性
对应对象:TScreen
声明:property Fonts:TStrings;
功能:Fonts属性说明了包含在应用程序中可用的字体例表。Fonts属性是只读型的,它包含了屏幕支持的字体例表,应用程序可用访问。用户可以使用Fonts属性来确定某种字体是否可以被使用,进而确定所使用的字体。

例子:
//Display all of the available fonts
procedure TForm1.FormCreate(Sender : TObject);
begin
ListBox1.Sorted := True;
ListBox1.Items := Screen.Fonts;
end;

FormCount属性
对应对象:TScreen
声明:property FormCount:Integer;
功能:FormCount属性包含了应用程序中屏幕上可以看到的窗体数目。它是只读型的。

例子:
//Get form count
procedure TForm1.Button1Click(Sender : TObject);
begin
Label1.Caption := ‘There is/are’ + IntToStr(Screen.FormCount) +
‘form(s) on the screen.’;
end;

Forms属性
对应对象:TScreen
声明:property Forms[Index:Integer] : TFonn;
功能:Forms属性对应了显示的窗体数组。在应用程序中的每一个窗体所对应的Forms数组中都给了一个确定的位置。程序创建的第一个窗体是Forms[0],第二个窗体是Forms[1],依此类推。Forms允许用户通过Index值访问应用程序的每—个窗体。

例子:
当按钮1被按击时,以下的代码加载了在屏幕上的所有的窗体名到ListBoxl上。
procedure TForm1.Button1Click(Sender : TObject);
var
I : integer;
begin
For I := 0 to Screen.FormCount – 1 do
ListBox1.Items.Add(Screen.Forms[I ].Name);
end;

Height属性
对应对象:TScreen
声明:property Height : Integer;
功能:Height属性包含有屏幕的高度。
Height属性是只读型的,包含有屏幕的垂直高度尺寸,并以象素来计数。

例子:
procedure TfrmScreenInfo.FormCreate(Sender : TObject);
begin
lblWidth.Caption := IntToStr(Screen.Width);
lblHeight.Caption := IntToStr(Screen.Height);
lblPixelsPerInch.Caption := IntToStr(Screen.PixelsPerInch);
end;

IconFont属性
对应对象:TScreen
声明:property IconFont : TFone;
功能:IconFont属性是说明了在文件选择对话框中,显示在图标上的标签的字体形式。

Imes属性
对应对象:TScreen
声明:property Imes : TStrings;
功能:Imes属性说明了在系统上安装的所有输入方法编辑器的例表。

Width属性
对应对象:TScreen
声明:property Width:Integer;
功能:Width属性说明了屏幕的宽度。这个属性是只读型的,包含有屏幕的水平尺寸,以象素来计数。示例:
with Screen do
for I := 0 to FormCount – 1 do
if Forms[I].Width > Width then Forms[I].Width := Width;

Create方法
对应对象:TScreen
声明:constructor Create(AOwner:TComponent);override;
功能:Create方法用来创建一个TScreen对象的实例。

Destroy方法
对应对象:TScreen
声明:destructor Destroy;override;
功能:Destroy方法用来消除一个TScreen对象的实例。

OnActiveControlChange事件
对应对象:TScreen
声明:TNotifyEvent = procedure(Sender :TObject)of object;
property OnActiveControlChange:TNotifyEvent;
功能:当屏幕的焦点从一个控件转换到另一个控件时发生OnActiveControlChange事件。如果每一次焦点的转换事件发生时用户希望应用程序处理一些操作的话,可以对OnActiveControlChange事件创建一个事件的处理代码来完成。当OnActiveCon-trolChange事件发生时,屏幕的激活控制属性的值将成为将要接收焦点的控件的属性值。

例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
Type
TForm1 = class(TForm)
RadioGroup1 : TRadioGroup;
RadioButton1 : TRadioButton;
RadioButton2 : TRadioButton;
RadioButton3 : TRadioButton;
CheckBox1 : TCheckBox;
CheckBox2 : TCheckBox;
Button1 : TButton;
Button2 : TButton;
Procedure FormCreate(Sender : TObject);
private
{Private declarations}
public
//Manually added method declaration
Procedure FocusChanged(Sender : TObject);
end;
var
Form1 : TForm1;
implementation
{$R *.DFM}

//Create an event handler for OnActiveControlChange
procedure TForm1.FormCreate(Sender : TObject);
begin
Screen.OnActiveControlChange := FocusChanged;
end;

//Respond to OnActiveControlChange events
procedure TForm1.FocusChanged(Sender : TObject);
begin
if Screen.ActiveControl = Button2 then
Button1.Enabled := False;
Else Button1.Enabled := True;
end;
end.

OnActiveFormChange事件
对应对象:TScreen
声明:TNotifyEvent = procedure(Sender:TObject) of object;
property OnActiveFormChange:TNotifyEvent;
功能:在激活的窗体被改变之前OnActiveFormChange事件发生。用户可以为OnActiveFormChange事件创建一个认为代码来实现在窗体改变之前希望完成的操作。

例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
Type
TForm1 = class(TForm)
RadioGroup1 : TRadioGroup;
RadioButton1 : TRadioButton;
RadioButton2 : TRadioButton;
RadioButton3 : TRadioButton;
CheckBox1 : TCheckBox;
CheckBox2 : TCheckBox;
Button1 : TButton;
Button2 : TButton;
Label1 : TLabel;
procedure FormCreate(Sender : TObject);
procedure Button1Click(Sender : TObject);
private
{Private declarations}
public
//Manually added method declaration
Procedure FormChanged(Sender : TObject);
end;
var
Form1 : TForm1;
implementation
uses Unit2;
{$R *.DFM}

//Create an event handler for OnActiveFormChange
procedure TForm1.FormCreate(Sender : TObject);
begin
Screen.OnActiveFormChange := FormChanged;
end;

//Handle the OnActiveFormChange event
procedure TForm1.FocusChanged(Sender : TObject);
begin
Label1.Caption := ‘Active Form is’ + Screen.ActiveForm.Name;
end;

//Show Form2 when the button is pressed
procedure TForm1.Button1Click(Sender : TObject);
begin
Form2.Show;
end;
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: