Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Alike editbox text action

Posted on 2004-04-22
11
Medium Priority
?
307 Views
Last Modified: 2010-08-05
I try to type into my TCustomControl a text. When the text length is bigger than my VCL width I wish to move the text to left as my rest part to fit into my canvas.

I try now to lead with Canvas.TextWidth but don't work very well :( Any unknown by me message to deal with text as TEdit ?

Any solution for this ? I will continue my work, but maybe someone have a better idea.
0
Comment
Question by:ginsonic
[X]
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
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10891822
Do you want it to work like to TEdit?

What is your canvas space?

SHane
0
 
LVL 9

Author Comment

by:ginsonic
ID: 10891920
Is width:=width-6 ( border 3 pixels left+3pixel rigth )
   heigth:=height-6 ( same idea );

But we can talk about a generic Width.Heigth
0
 
LVL 17

Assisted Solution

by:mokule
mokule earned 400 total points
ID: 10891928
Hi
What about ?

    procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Accepted Solution

by:
shaneholmes earned 800 total points
ID: 10891990
You will need to test for a CMTextChanged message, then compare the TextWidth against the workarea of your control.
 If its greater, then repaint the text, minus the overlapping width.


Shane
0
 
LVL 9

Author Comment

by:ginsonic
ID: 10892716
I do already this but look alike my Canvas.TextWidth(Text)-6 ( the border ) don't work well for different fonts size. The Font is assigned to Canvas.Font;
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10892817
Did you try using the TextExtent method

 - Returns the width and height, in pixels, of a string rendered in the current font.

Shane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10892920
Shane:
TextExtent returns the same width as TextWidth.

ginsonic:
What fonts do You try? Can precise what does that mean don't  work well?
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10893020
Mokule - I know its the same width - thanks for the education.....

I was letting ginsonic know about the method case he didn't know it existed, seeing he is creating a derived control from TCustomControl, and he might want to adjust the height as well, due to different fonts (which effect not only width)

How about that Mr. Snap!

Shane
0
 
LVL 34

Assisted Solution

by:Slick812
Slick812 earned 400 total points
ID: 10893034

I always use the API DrawText  function for any text that I need to be within a Rectangle or looks like some windows control

var
TextRect: TRect;
Text: String;
Format: Cardinal;
begin
Text := 'This is the text to put in the Rectangle';
TextRect := Rect(3,3, width-6, height-6); // set this Rect to the size of  your display  text area
if Canvas.TextWidth(Text) > TextRect.Right - TextRect.Left then
  Format := DT_SINGLELINE or DT_RIGHT else  // DT_RIGHT will push all text to the left so the last charater is on the right of rectangle
  Format := DT_SINGLELINE;
DrawText(Canvas.Handle,PChar(Text),-1,TextRect, Format);
end;


there are many other Format flags that you can use (like DT_EXPANDTABS) which might help you for your display, you might experiment with some of these to see if it will put the text into your control like an Edit
0
 
LVL 3

Assisted Solution

by:Kunfufaresi
Kunfufaresi earned 400 total points
ID: 10893536
Hello,

I remember having a similar problem, the textextent doesnt account for italic or kerning settings... at least that was my impression of it, when painting using drawtext and defining textrect accorting to textextent data.

As far as I got couldnt find any real solution to the dilema, my code was like

var
 Tsizex         : TSize;
...
begin
  Tsizex := newimage.Canvas.TextExtent('this is the string');
  Newimage.Canvas.TextRect(Rect( 10,10,10+Tsizex.cx,10+Tsizex.cy), 0,0,'this is the string');
end;

But you might try starting the painting from -3,0 or something like that.

Ekim
0
 
LVL 9

Author Comment

by:ginsonic
ID: 10900446
.FIx my problem. Still use TextWidth. The problem start from using FText of VCL instead of FDisplayed text.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

598 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