Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Controlling the keyboard cursor in TEdit

Posted on 1997-08-28
4
470 Views
Last Modified: 2009-07-29
I just tried to customize an edit control to change some
of its keys. I wish for the control to display a different
character instead of the one clicked. For example: I'll
click '1' and it'll add '2' instead. I have the translation
table I need.
What I did it to add an event handler to the KeyPress
/KeyDown events. My event handlers would temporarily
make the TEdit compo ReadOnly so that it won't respond
to the actual key pressed. The second thing I did was
to alter the edit's text property.

Eg. Edit1. Text:= Edit1. Text + 'A';

My problem: when I change the text property the text
cursor is automatically moved to the beginning of the
edit field hence not allowing me to normally use the
edit functions.

I can override the other keys ( left, right, backspace... )
to do what is needed but I wish that damn cursor to be
where it is supposed to be.

How?

Another thing, how can I change the TEdit's text alignment?

0
Comment
Question by:nir_l
4 Comments
 
LVL 1

Expert Comment

by:sassas081597
ID: 1342884
To the second question:

hRightEdit:=CreateWindow('edit',nil, ws_Child or ws_VISIBLE or WS_BORDER or WS_SCROLL or {this is the case} ES_RIGHT or es_AUTOSCROLL or ES_MULTIlINE, 100, 100, 200,100, WINDOW, HMENU(-1), hInstance, nil);

For more comment look in Help file.
0
 

Accepted Solution

by:
khenr29j earned 150 total points
ID: 1342885
The easiest way of doing what you want is to add an OnKeyPress event handler that modifies the Key parameter.
The following code will replace each character pressed by an 'a':

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  Key := 'a';
end;

0
 

Expert Comment

by:krisz
ID: 1342886
There is also a way to change the position of the caret
(the cursor), and change the selection.

It's enough in a comment.
0
 

Author Comment

by:nir_l
ID: 1342887
khenr29j...
Ok, I thank you for that. It's irritating when the most simple things sometimes get out of your eye. However, you didn't answer the alignment thing nor the cursor play thing.

sassas...
Thanks for the tip. However, I think it's better either creating a new control overriding the CreateParams method or using the WindowSetLong procedure. The first of my suggestions works fine but for some wierd reason I can't yet activate the second. Check it out if you like.

krisz...
I know the API procedures for changing the caret position but it's using pixels and not characters and messing with font widths seems to me too much.

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Downloading email attachments 2 79
tvirtualstringtree freeze when load too manny images 10 71
Adoquery sql  left join does not work 25 98
Twebbrowser add css to the header 3 27
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question