如何做这样的Edit控件,恳请帮忙! ( 积分: 75 )

  • 主题发起人 主题发起人 qylin1
  • 开始时间 开始时间
Q

qylin1

Unregistered / Unconfirmed
GUEST, unregistred user!
1.可以设置垂直对齐方式。
2.可以设置能否编辑。(注意:不是简单的ReadOnly,看下面)
3.当设置为不可编辑时,隐藏输入光标(就是那个一闪一闪的小竖线)
4.当设置为不可编辑时,允许获得焦点。

我的分数只有这么多,希望各位不要嫌少,来帮帮忙,谢谢啦
 
1.可以设置垂直对齐方式。
2.可以设置能否编辑。(注意:不是简单的ReadOnly,看下面)
3.当设置为不可编辑时,隐藏输入光标(就是那个一闪一闪的小竖线)
4.当设置为不可编辑时,允许获得焦点。

我的分数只有这么多,希望各位不要嫌少,来帮帮忙,谢谢啦
 
Edit就一行啊,怎样垂直对齐?
不可编辑时就让它隐藏了算了,可编辑时,显示并获得焦点就是
 
不可编辑的时候直接enabled:=False吧
 
谢过楼上两位,不过如果能用Visible或Enabled来搞定的话,我就不用来麻烦大家啦,因为无论无论Visible或Enabled设置为False后,控件就无法获得焦点啦!

小弟急用呀,还请各位帮帮忙吧,感谢!
 
你想怎么对齐?几个edit的对齐?

你想隐藏光标的同时还想获得焦点??
 
To:hs-kill
对齐是指 Edit 控件的 Text 文本可以设置居上、居中、居下
要求是隐藏光标的时候可以获得焦点,就好象 Style=csDropDownList 的 ComboBox 一样,可以得到焦点,但不显示输入光标
 
自己顶上去,再请帮忙!
 
听课。。。。
 
等高手讲课。。。。
 
汗。。。。。edit就一行,你怎么设置居上、居中、居下 -_-!
要是多行那不就变成了memo。。。。。

至于隐藏光标。。。暂时没想到办法。。。-_-!
 
自己顶上去,再请帮忙!
 
楼主要求的对齐方式,实在无聊得很,我不干,找无聊人去干。Edit那个不是光标,
是插字符,可以按下面的代码禁止edit1闪动插字符,不会影响焦点。
procedure TForm1.FormActivate(Sender: TObject);
begin
if edit1.ReadOnly then
Windows.HideCaret(edit1.handle);//要在窗体的Activate事件里面写
end;
要成功,楼主记住给我打分,另外转贴的网友请加本贴网址。
 
楼上的 那样不行,edit失去焦点后再获得又会出现光标的
 
加入
procedure TForm1.Edit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Windows.HideCaret(edit1.handle);
end;
再不行的话,就拦截Enter消息,在里面干活!
 
To:kinneng
首先谢过大哥的帮忙,用HideCaret的方法我试过了,单在MouseDown处理是不够的,还要在KeyUp中处理,但在获得焦点时,那根小竖线还是会闪现一下,虽然可以马虎应付,但我还是希望能有完全不显示的办法,希望高手们再帮帮忙。
另,我也试过拦截Enter消息,但毫无作用,也许是我的方法不对吧!

至于对齐方式,我实有这个需求,而且我并不觉得无聊,想必在这的朋友们都用过FrontPage,都能看得懂以下这个语句:<td valign="middle" align="center"></td>吧,这是定义一个水平居中垂直也是居中的单元格,如果这也是无聊的话,Microsoft 不早关门了么。
 
......那是table。。。。。。
 
其实,我明白你对齐的意思,因为我的网站也干这活,
继承一个Edit,然后拦截WM_SETFOCUS消息,焦点没影响,且没有光标

type
TEXEdit = class(TMaskEdit)

procedure WMSETFOCUS(var Message:TMessage);message WM_SETFOCUS;

procedure TEXEdit.WMSETFOCUS(var Message:TMessage);
begin
if not ReadOnly then inherited;
end;
 
对齐方式我在几个帖子里面都写过了,网上也有很多代码

SetWindowLong(Edit1.Handle,GWL_STYLE, GetWindowLong(Edit1.Handle, GWL_STYLE)
or [blue]ES_RIGHT[/blue]); 蓝色部分是你自己要去找MSDN和Delphi帮助的,

下面的东西,ReadOnly是要的,然后修改下背景色,还有个API函数HideCaret,隐藏光标
HideCaret(控件Handle),不过好像没作用,郁闷[:(][:(]


我把分格贴上

Edit Styles
ES_AUTOHSCROLL Automatically scrolls text to the right by 10 characters when the user types a character at the end of the line. When the user presses the ENTER key, the control scrolls all text back to position 0.


ES_AUTOVSCROLL Automatically scrolls text up one page when the user presses ENTER on the last line.


ES_CENTER Centers text in a single-line or multiline edit control.


ES_LEFT Left-aligns text in a single-line or multiline edit control.


ES_LOWERCASE Converts all characters to lowercase as they are typed into the edit control.


ES_MULTILINE Designates a multiple-line edit control. (The default is single line.) If the ES_AUTOVSCROLL style is specified, the edit control shows as many lines as possible and scrolls vertically when the user presses the ENTER key. If ES_AUTOVSCROLL is not given, the edit control shows as many lines as possible and beeps if ENTER is pressed when no more lines can be displayed. If the ES_AUTOHSCROLL style is specified, the multiple-line edit control automatically scrolls horizontally when the caret goes past the right edge of the control. To start a new line, the user must press ENTER. If ES_AUTOHSCROLL is not given, the control automatically wraps words to the beginning of the next line when necessary; a new line is also started if ENTER is pressed. The position of the wordwrap is determined by the window size. If the window size changes, the wordwrap position changes and the text is redisplayed. Multiple-line edit controls can have scroll bars. An edit control with scroll bars processes its own scroll-bar messages. Edit controls without scroll bars scroll as described above and process any scroll messages sent by the parent window.


ES_NOHIDESEL Normally, an edit control hides the selection when the control loses the input focus and inverts the selection when the control receives the input focus. Specifying ES_NOHIDESEL deletes this default action.


ES_OEMCONVERT Text entered in the edit control is converted from the ANSI character set to the OEM character set and then back to ANSI. This ensures proper character conversion when the application calls the AnsiToOem Windows function to convert an ANSI string in the edit control to OEM characters. This style is most useful for edit controls that contain filenames.


ES_PASSWORD Displays all characters as an asterisk (*) as they are typed into the edit control. An application can use the SetPasswordChar member function to change the character that is displayed.


ES_RIGHT Right-aligns text in a single-line or multiline edit control.


ES_UPPERCASE Converts all characters to uppercase as they are typed into the edit control.


ES_READONLY Prevents the user from entering or editing text in the edit control.


ES_WANTRETURN Specifies that a carriage return be inserted when the user presses the ENTER key while entering text into a multiple-line edit control in a dialog box. Without this style, pressing the ENTER key has the same effect as pressing the dialog box’s default pushbutton. This style has no effect on a single-line edit control.
 
有上中下对齐吗?
 

Similar threads

D
回复
0
查看
836
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
681
DelphiTeacher的专栏
D
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部