怎样是TEdit里的内容居右显示?
解决方案 »
- 风传寒信,遥念故人
- 刚带女友打胎回来,在一个小诊所花了100多块钱,大医院要上千,太贵,有那钱我还吃饭馆呢。
- delphi6下开发的com+组件在客户端无法访问!已经在网上搜索三天了!!!急救!!!
- 如何用delphi实现ftp下载文件
- 关于事务的问题
- quickreport 的问题
- 做个商业软件是否要交gif编码版权费给Unysis公司呢?
- ICS控件组的Ping控件在哪里找?????自带的么?我真的找不到哦???
- 3层关于容错处理的问题
- treeview 控件问题,
- NMHTTP不懂用,写的程序老报错,郁闷ing 源码如下,哪位同志肯帮我分析一下,谢谢
- 请问:怎么样打印image里面的picture 啊》?》》
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if NOT (key in ['0'..'9']) then Key=#0;
end;
//彻底的办法 自定义控件
unit XEdit;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TXCustomEdit = class(TCustomEdit)
private
FAlignment: TAlignment;
FAutoTab: Boolean;
FNumber: Boolean;
procedure SetAlignment(const Value: TAlignment);
procedure CNKeyDown(var Message: TWMKeyDown); message CN_KEYDOWN;
procedure SetNumber(const Value: Boolean);
protected
procedure CreateParams(var Params: TCreateParams); override;
public
constructor Create(AOwner: TComponent); override;
published
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
Property AutoTab: Boolean Read FAutoTab Write FAutoTab default True; Property Number: Boolean Read FNumber Write SetNumber Default False;
end;
{TEditEx}
TXuEdit = class(TXCustomEdit)
published
property Anchors;
property AutoSelect;
property AutoSize;
property BevelEdges;
property BevelInner;
property BevelKind default bkNone;
property BevelOuter;
property BiDiMode;
property BorderStyle;
property CharCase;
property Color;
property Constraints;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property ImeMode;
property ImeName;
property MaxLength;
property OEMConvert;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;
implementation
{实现}
procedure TXCustomEdit.CNKeyDown(var Message: TWMKeyDown);
begin
if (Message.CharCode=VK_RETURN) AND FAutoTab then
Message.CharCode:=VK_TAB;
inherited;
end;
constructor TXCustomEdit.Create(AOwner: TComponent);
begin
FAutoTab:=True;
FNumber:=False;
FAlignment:=taLeftJustify;
inherited Create(AOwner);
end;
procedure TXCustomEdit.CreateParams(var Params: TCreateParams);
const
Alignments: array[Boolean, TAlignment] of DWORD = ((ES_LEFT, ES_RIGHT, ES_CENTER),(ES_RIGHT, ES_LEFT, ES_CENTER));
NumberSet: Array[Boolean] of DWORD =(0, ES_NUMBER);
begin
inherited CreateParams(Params);
with Params do
begin
Style := Style or Alignments[UseRightToLeftAlignment, FAlignment] or NumberSet[FNumber];
end;
end;
procedure TXCustomEdit.SetAlignment(const Value: TAlignment);
begin
if FAlignment <> Value then
begin
FAlignment := Value;
RecreateWnd;
end;
end;
procedure TXCustomEdit.SetNumber(const Value: Boolean);
begin
if FNumber <> Value then
begin
FNumber := Value;
if FNumber then FAlignment:= taRightJustify;
RecreateWnd;
end;
end;
{Register 就自己写吧}
end.
const
Alignments: array[Boolean, TAlignment] of DWORD = ((ES_LEFT, ES_RIGHT, ES_CENTER),(ES_RIGHT, ES_LEFT, ES_CENTER));
NumberSet: Array[Boolean] of DWORD =(0, ES_NUMBER);
begin
inherited CreateParams(Params);
with Params do
begin
Style := Style or Alignments[UseRightToLeftAlignment, FAlignment] or NumberSet[FNumber];
end;
end;
楼上的已经给出了核心的代码,OVERRIDE并少改一下就OK了,
我一向都用FORMAT输出的..简单又快..何必...当然..我很佩服这个写控件的兄弟...
在2003server下面似乎绝大多数标准control都能左右互换,工作正常,尤其是光标。var
windowStyle: cardinal;
begin
windowStyle :=GetWindowLong(edit1.Handle,GWL_EXSTYLE);
if (windowStyle and WS_EX_LAYOUTRTL) = WS_EX_LAYOUTRTL then
windowStyle := windowStyle - WS_EX_LAYOUTRTL
else if (windowStyle and WS_EX_LAYOUTRTL) = 0 then
windowStyle := windowStyle + WS_EX_LAYOUTRTL
else ; SetWindowLong(edit1.Handle, GWL_EXSTYLE,windowStyle);
//SendMessage(edit1.Handle, EM_SETSEL, 0, MAKELONG($ffff, $ffff));
InvalidateRect(edit1.Handle, nil, TRUE);
end;p.s.如果windowStyle := windowStyle + WS_EX_LAYOUTRTL符号搞错,可以mirror。