I'm implementing a TListView in a Firemonkey app, where the height of each list item must be as small as possible, just large enough to fit the text. However, there is an apparent margin on the top of the text, leaving an empty space at the beginning of each list item.
The item appearance is set to ListItemRightDetail, but I cannot find any properties anywhere to allow me to control this - neither in the FMX design or the Styles for the List View.
How do I eliminate the margin at the top of list item text so that I can minimize the list item heights?
There are not necessarily any "margin" properties, as this margin is pretty much built-in. However, this can be adjusted by modifying the PlaceOffset.Y property, and making them a negative value. This will "lift up" the contents within each list item. I find -3 to be a sufficient amount to reduce this margin...
ListView1.ItemAppearanceObjects.ItemObjects.Text.PlaceOffset.Y := -3;
ListView1.ItemAppearanceObjects.ItemObjects.Detail.PlaceOffset.Y := -3;
Related
I'm trying to make a Rectangle to show some information. Inside this Rectangle I have a lot of labels, and in this labels I want to show some texts in bold. For example: 'Name:' <- Bold, and after this not bold.
If this is not possible, how can I know the size in pixels of a label.text? If I have this information, I can create two label and set the position of the second to be: label2.position.X := label1.textWidth;
Thanks!
Using the standard label control your only option is to use two such controls, one with Font.Style including fsBold, the other not.
Place your first, bold label then as long as you leave/set the AutoSize property true, the Width property will tell you the width:
// Where:
//
// - boldLabel is a created, initialised and positioned
// label with bold text
//
// - normalLabel is a created and initialised label which
// has not yet been positioned (horizontally)
//
// - spacingPixels is the distance you wish to maintain
// between the two
normalLabel.Position.X := boldLabel.Position.X + boldLabel.Width + spacingPixels;
There are a number of 3rd party label controls, many of them free + open source (for VCL [see below]), which support varying degrees of markup in a label. There may be similar implementations for FMX.
For VCL projects you might want to check out the JediVCL library which includes a label supporting not just bold but other, albeit limited HTML markup. If this is of interest, the control you are looking for in that library is TJvHTLabel.
NB. For future ref: You don't specify whether your project is FMX or VCL but it appears from the use of the Position property that it is likely to be FMX. For issues involving controls, the framework in use can be a significant factor and should be mentioned to avoid eliciting answers that may not be relevant.
I use Borland C++ Builder 2009 (yet I assume the issue and solution is the same for Delphi) and right now I assume the answer I'm looking for is the same for both TListView items and TTreeView items. I may be wrong !?
I have noticed, on a smaller Win 8.1 laptop with Display setting 'Change the size of all items' set to 125% . That the items in both TreeView and ListView get closer to each other.
I haven't tested 150% yet, I assume it will be worse.
I would like to adjust for that if possible.
I assume the same logic goes for when a larger sized font is chosen to display these items ?
How would you test if the height of the items is 'too' big and the items need a bit more space between them ?
And how would you increase the spacing between them ? Taking in account that my ListView implementation is virtual (ListView->OwnerData = true ;) !
TForm has Scaled property. If it is true, all components on a form should be resized automatically accordingly to font size. I cannot check right now if this works for TListView and TTreeView, but you should check this property anyway.
I have a gui that keeps scrolling on the 8520 screen. I have used setPadding(XYEdges) and setMargin(XYEdges) to remove the spaces around the components on the UI but there's still space left in between these components. Are there other API calls i can make to remove spaces around components?
You need to consider the following:
setPadding refers to a boundary inside the border of a field and controls how close the internal content of the field can be to the border.
setMargin refers to a boundary outside the border of a field and controls how close the field can be to an adjacent field on that edge.
BUT note that the margins of adjacent fields overlap, so that if field A has it's right margin set to 0, and right adjacent field B has it's left margin set to 20, then the two fields will still be placed no closer than 20 pixels apart.
i.e. you have to take into account the margins set for the edges of all adjacent fields.
Returning to padding, the same applies for managers if you set their internal padding. This will determine how close to the inside of the manager's border an included field can be placed.
Somewhere in the blackberry documentation and/or support forum, there is a document explaining this pictorially, I just can't find my link to it right now, but will post it here when I find it again.
Scrolling a TStringGrid using its horizontal scroll bar will scroll a column at a time. In some situations, this creates a really nasty behavior that makes the grid unusable: if the width of last column is large (example, 1000 pixels) the user won't be able to scroll the grid to see the entire content of the column.
There is a way to scroll by pixel? Or to set the correct scroll range for grid's scroll bar?
As far as I know, no you can't horizontally scroll the string or draw grids by pixels, only by whole columns. I agree it can be a problem by the way. I tend to autosize the columns but make the max initial size of any column be slightly less than the clientwidth of the control.
I have looked into the source code. With Borland's code it can't be done.
However, Lazarus has this capability.
I've got a TCheckListBox on a form. Its Columns property is set to 2, and if there are more items than can fit on-screen in two columns, it puts a horizontal scrollbar across the bottom of the control.
Thing is, the way this form it laid out, it would be much more convenient to scroll vertically. But I can't seem to figure out how to make the box do that. I thought setting Columns to 1 should work, but it doesn't.
Anyone know how to make a TCheckListBox scroll vertically instead of horizontally?
You need to set Columns to 0.
For all positive values the VCL sends a LB_SETCOLUMNWIDTH message to the underlying native list box control, with the width parameter set to the list box client width divided by the number of columns. Items that don't fit will start a new column with the same column width, so the horizontal scrollbar becomes visible.
If Columns is 0 then there is a single column that spans the entire client width of the list box, and items that don't fit will make the vertical scrollbar visible, and hide the horizontal scrollbar.
Edit:
There seems to be genuine interest what happens when a negative value is used for the Columns property.
The method TCustomListBox.CreateParams() sets the LBS_MULTICOLUMN list box style depending on the Columns property being different from 0. For negative values the style flag is set, but the VCL doesn't send the LB_SETCOLUMNWIDTH message, so the native control uses the default column width. It is documented to be:
15 times the average character width for the font used by the list box.
(Search for "The LBS_MULTICOLUMN style specifies" to find the relevant passage of text.)