zoukankan      html  css  js  c++  java
  • 调整 TEdit 文本对齐

    譬如让 Edit1 文本右对齐:
    SetWindowLong(Edit1.Handle, GWL_STYLE, GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_RIGHT);

    本例效果图:


    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;
    
    type
      TForm1 = class(TForm)
        Edit1: TEdit;
        RadioGroup1: TRadioGroup;
        procedure FormCreate(Sender: TObject);
        procedure RadioGroup1Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      RadioGroup1.Items.CommaText := 'Left,Center,Right';
      RadioGroup1.ItemIndex := 0;
    end;
    
    procedure TForm1.RadioGroup1Click(Sender: TObject);
    var
      es: Integer;
    begin
      es := GetWindowLong(Edit1.Handle, GWL_STYLE) or 3;
      es := es xor (3 - RadioGroup1.ItemIndex);
      SetWindowLong(Edit1.Handle, GWL_STYLE, es);
      Edit1.Refresh;
    end;
    
    end.
    
    这里面有个问题需要知道: 决定对齐方式的三个常量值 ES_LEFT、ES_CENTER、ES_RIGHT 分别是 0、1、2, 刚好可以对应 RadioGroup1.ItemIndex; 再换一种思路实现一下:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;
    
    type
      TForm1 = class(TForm)
        Edit1: TEdit;
        RadioGroup1: TRadioGroup;
        procedure FormShow(Sender: TObject);
        procedure RadioGroup1Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    var
      es_bak: Integer;
    
    procedure TForm1.FormShow(Sender: TObject);
    begin
      RadioGroup1.Items.CommaText := 'Left,Center,Right';
      es_bak := GetWindowLong(Edit1.Handle, GWL_STYLE);
    end;
    
    procedure TForm1.RadioGroup1Click(Sender: TObject);
    var
      es: Integer;
    begin
      es := es_bak or RadioGroup1.ItemIndex;
      SetWindowLong(Edit1.Handle, GWL_STYLE, es);
      Edit1.Refresh;
    end;
    
    end.
    
  • 相关阅读:
    洛谷【P1177】【模板】归并排序
    洛谷【P1177】【模板】快速排序
    洛谷【P1104】生日(冒泡排序版)
    洛谷【P1104】生日(插入排序版)
    洛谷【P1104】生日(选择排序版)
    BZOJ5443:[CEOI2018]Lottery
    ReactNative---ref的用法和技巧
    ios---运用MJRefresh组件设置下拉刷新
    ReactNative---setState与性能的平衡
    ios---设置UITabBarController的字体颜色和大小
  • 原文地址:https://www.cnblogs.com/del/p/1179416.html
Copyright © 2011-2022 走看看