zoukankan      html  css  js  c++  java
  • Delphi 之 标签组件(TLabel组件)

      标签组件是比较常用的组件,现在来看看标签组件的常用的基本属性:

    Align 

       它的作用是和窗体对齐,对齐的方式有alNone, alTop, alBottom, alLeft, alRight, alClient, alCustom.

    Alignment 

         它的作用是标签文本显示的位置,对齐方式为taLeftJustify, taRightJustify, taCenter意思为左边,右边,中间

    autosize  

      自动调整标签的大小。true为自动大小,flase为不改变大小。

    FocusControl

      与某个控件相关联,通常与ShowAccelChar一起使用。当ShowAccelChar为True时,可以使用一个加速键,在标签上使用&符号。此时Alt+快捷键才有效果。

    此时按下ALT+F键会切换文本框F,若按下ALT+G键会切换文本框G中

    ShowAccelChar 

      该属性确定True时,使用&符号时,文本上会显示一个下划线。

    标签的时间属性

    OnMouseEnter

      鼠标移动到标签上的事件。

    OnClick

      鼠标单击事件

    OnMouseLeave

      鼠标离开事件

    结合实例演示,当鼠标移动到标签上显示下划线。离开时下划线消失。当鼠标单击获取文本框焦点或按下快捷键切换焦点。

     

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        Edit1: TEdit;
        Edit2: TEdit;
        procedure FormCreate(Sender: TObject);
        procedure Label1MouseEnter(Sender: TObject);
        procedure Label1MouseLeave(Sender: TObject);
        procedure Label1Click(Sender: TObject);
        procedure Label2MouseEnter(Sender: TObject);
        procedure Label2MouseLeave(Sender: TObject);
        procedure Label2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Label1.Alignment:= taCenter;
    
    
    end;
    
    procedure TForm1.Label1MouseEnter(Sender: TObject);
    begin
      (sender as TLabel).Font.Style:= [fsUnderline];
    end;
    
    procedure TForm1.Label1MouseLeave(Sender: TObject);
    begin
      (Sender as TLabel).Font.Style:=[];
    end;
    
    procedure TForm1.Label1Click(Sender: TObject);
    begin
      if(Sender as TLabel).Name = 'Label1' then
        Edit1.SetFocus
      else
        Edit2.SetFocus;
    end;
    
    procedure TForm1.Label2MouseEnter(Sender: TObject);
    begin
      (Sender as TLabel).Font.Style:=[fsUnderline];
    end;
    
    procedure TForm1.Label2MouseLeave(Sender: TObject);
    begin
      (Sender as TLabel).Font.Style:=[];
    end;
    
    procedure TForm1.Label2Click(Sender: TObject);
    begin
      if(Sender as TLabel).Name = 'Label2' then
        Edit2.SetFocus
      else
        Edit1.SetFocus;
    
    end;
    
    end.

     源码下载地址:http://files.cnblogs.com/delphi2014/%E6%A0%87%E7%AD%BE1.zip

  • 相关阅读:
    toolblock 编写脚本并运用。
    C#等待子线程执行完毕
    win10+python3.7+dlib+opencv+face_recognition实现人脸识别
    c# tcp/ip通信
    【微信Xposed】kotlin反射异常RuntimeException:looper or serial is null
    安卓APK开启调试
    常用汇编指令对标志位的影响
    简单的.net反调试,调试检测
    虚拟机VMware和win10 hyper-v不兼容的问题
    对某城APP抓包分析--过SSL证书校验
  • 原文地址:https://www.cnblogs.com/delphi2014/p/4015701.html
Copyright © 2011-2022 走看看