我的DBeidt显示的时候,字符串的是左对齐,而数字是右对齐,当聚焦到显示数字的DBedit后又变成左对齐了,就这样的乱跳,闹心死了,我想让他们都左对齐,看过以前的解决方法,但是这个方法对显示数字的DBedit好像没有作用,请大虾们帮俺看看,究竟怎么解决这个问题啊改变DBeditunit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, StdCtrls, Mask, DBCtrls;type
TDBEdit = class(DBCtrls.TDBEdit)
private
FAlignment : TAlignment;
procedure SetAlignment(Value: TAlignment);
protected
procedure CreateParams(var Params: TCreateParams); override;
public
property Alignment: TAlignment read FAlignment write SetAlignment;
end;type
TForm1 = class(TForm)
DBEdit1: TDBEdit;
DataSource1: TDataSource;
Table1: TTable;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TDBEdit.CreateParams(var Params: TCreateParams);
const
Alignments : array[TAlignment] of LongWord= (ES_Left,ES_Right, ES_Center);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or Alignments[FAlignment];
end;procedure TDBEdit.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value then
begin
FAlignment := Value;
RecreateWnd;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
DBEdit1.Alignment := taLeftJustify; // 设成左对齐
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, StdCtrls, Mask, DBCtrls;type
TDBEdit = class(DBCtrls.TDBEdit)
private
FAlignment : TAlignment;
procedure SetAlignment(Value: TAlignment);
protected
procedure CreateParams(var Params: TCreateParams); override;
public
property Alignment: TAlignment read FAlignment write SetAlignment;
end;type
TForm1 = class(TForm)
DBEdit1: TDBEdit;
DataSource1: TDataSource;
Table1: TTable;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TDBEdit.CreateParams(var Params: TCreateParams);
const
Alignments : array[TAlignment] of LongWord= (ES_Left,ES_Right, ES_Center);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or Alignments[FAlignment];
end;procedure TDBEdit.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value then
begin
FAlignment := Value;
RecreateWnd;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
DBEdit1.Alignment := taLeftJustify; // 设成左对齐
end;end.
一个简单的办法就是sql的时候把数字转换成字符串显示
字段值的显示并不是在dbedit中设置,而实在数据表table控件的各个字段上设置的。
然后DateSource1连的ADOTable1
DBNavigator1的DateSource设为DateSource1,
DBEdit1的DateSource设为DateSource1,DateField为CustomerID(integer型)现在我想点击一下DBNavigator1的按钮,在DBEdit1中显示相应的CustuomerID
由于CustomerID是integer型的,所以DBEdit1中是靠右显示的,我想把它改成靠左显示我该怎么办?
在FormCreate里加上
DBEdit1.Field.Alignment := taLeftJustify;
就好了