I have several memos with different font on QuickReport. Now I'd like to know the most bottom point for all (for set some shape below). How? If I calculate TextHeight for each and multiple by lines count (aMemo.ParentReport.TextHeight(aMemo.Font, 'W') * aMemo.Lines.Count), results are not correctly - QuickReport print lines like with strange height and position of my shape for some fonts are too high or too low.
Ok, I got it. TextHeight cannot be call from QuickReport, but from Printer.Canvas. Then divide it by Y-Resolution for printer, next divide by 254 and multiple by 96. Result will be round and this is real value of Height of text in TQRMemo. All values are not accessible before print from QuickReport. It's very "smart" to return not real values based on same properties like during printing by component (by TQuickRep.TextHeight method).
I was a dynamic data, and I want to show it on the same TChart. How can I fix the axis margin with different data?
For Example:
First Data Have a 'thousand' value
Second Data Have a 'hundred' value
I want my TChart have same margin for any value. Thanks in advance
I think you can set it by forcing the label width to a given value.
TChart1.Axis.Left.Labels.Size := 30;
So that it always stay at the same width.
With the interface it's here
I have numerous text boxes on an MS-Access form where I'm using left align, but I'd prefer to have a space or two between the edge of the actual box when it displays and the start of the actual data. I thought using the left padding item on the text box property sheet, but it doesn't seem to make any difference. I've tried using the format property like this: " " & fieldname but I got an error saying it didn't recognize the field name. I'd appreciate any help you could provide. Thanks.
If I set the property LeftMargin of a textbox from the default 0 to some value, the content is indented as expected by that value.
I have a binding for a rectangle on an canvas like this:
xLeft.textProperty().bind(fieldCanvas.layoutXProperty().asString());
The value returned in the TextField is returned with one decimal place. Since I'm working with pixels, I'm trying to get rid of the DP i.e. display as an integer.
How can I format the DoubleProperty (layoutXProperty) to zero DP?
xLeft.textProperty().bind(fieldCanvas.layoutXProperty().asString("%.0f"));
It's a TMemo, not that that should make any difference.
Googling suggests that I can use Canvas->TextWidth() but those are Delphi examples and BCB doesn't seem to offer this property.
I really want something analogous to memo->Font->Height for width.
I realize that not all fonts are fixed width, so a good estimate will do.
All that I need is to take the width of a TMemo in pixels and make a reasonable guess at how many characters of the current font it will hold.
Of course, if I really want to be lazy, I can just google for the average height/width ratio, since height is known. Remember, an approximation is good enough for me if it is tricky to get exact.
http://www.plainlanguagenetwork.org/type/utbo211.htm says, " A width to height ratio of 3:5 (0.6) is recommended for most applications"
Actually your google search is not entirely off. You do need access to a canvas object, or at least a handle to a DC object. In general when searching for help concerning VCL classes it often pays to search for delphi examples since these are more common.
Anyway to calculate the size of a string you could have a look at the TextExtent function, it is a function for the TCanvas class. Simply pass the character which width you want to test, and the return value will be a TSize construct. However there is also a TextWidth function, as well as a TextHeight function. You can use these as well. Actually these call the TextExtent internally.
You have to note one thing though, the functions use the current font of the TCanvas object, more specifically the font bound to the DC the canvas uses. So assign the font you wish to test with first, and then pass the character.
I have some old code that calculates the width of a string like this:
// This canvas could be the form canvas: canvas = Form1->Canvas or the
// memo canvas which will probably be what you want.
canvas->Font->Assign(fontToTest);
int textwidth = TextWidth(textToTest);
If you want more control of what to do, you can also do this using the Windows API, this is essentially what the VCL does for you, in that case the following example would look like this:
// This canvas could be the form canvas: canvas = Form1->Canvas
canvas->Font->Assign(fontToTest);
// The initial size, this is really important if we use wordwrapping. This is
// the text area of the memo control.
TRect rect = ClientRect;
// This is the font format we wish to calculate using, in this example our text
// will be left aligned, at the top of the rectangle.
fontformat = DT_LEFT | DT_TOP;
// Here we calculate the size of the text, both width and height are calculated
// and stored in the rect variable. Also note that we add the DT_CALCRECT to the
// fontformat variable, this makes DrawTextEx calculate the size of the text,
// without drawing it.
::DrawTextEx(canvas->handle,
textToTest.c_str(),
textToTest.Length(),
&rect,
fontformat | DT_CALCRECT,
NULL);
// The width is:
int width = rect.Width();
The fontformat is a parameter that specifies different options for how to align and layout the text, if you plan on drawing text it will be a good idea to check out the different possibilities it offers: DrawTextEx Function [1]
EDIT: Reading through your question again, it struck me that the function you might be searching for is: GetTextExtentExPoint Windows API documentation states the following about this function:
The GetTextExtentExPoint function
retrieves the number of characters in
a specified string that will fit
within a specified space and fills an
array with the text extent for each of
those characters. (A text extent is
the distance between the beginning of
the space and a character that will
fit in the space.) This information is
useful for word-wrapping calculations.
You can find more information about the GetTextExtentExPoint function here: GetTextExtentExPoint Function [2]
[1] http://msdn.microsoft.com/en-us/library/dd162499%28VS.85%29.aspx
[2] http://msdn.microsoft.com/en-us/library/dd144935%28VS.85%29.aspx
What you could do, if you have access to Win32 API functions, is create a RichEdit Window the same size as your TMemo window, place the text in the RichEdit window, send the EM_FORMATRANGE message to the window and from the result determine how many characters it will hold. Of course this method will work with multiple lines etc...