I want to make a label, that occupies all empty space, and at the same time has centered text.
// firemonkey code,
// causes compile-time error "E2010 Incompatible types: 'TAlignLayout' and 'Set'"
GreedyLbl.Align := [TAlignLayout.alClient, TAlignLayout.alCenter];
I've also looked for a suitable constant on embarcadero wiki, but with no result. Maybe someone knows how can I make a described label?
It looks like you're pretty close. Try setting the Align to just TAlignLayout.alClient. Then set the TextAlign to TTextAlign.taCenter.
The Align property is part of TControl and comes into play anytime there is a control with a visual aspect to it.
The TextAlign property only involves controls descended from TTextControl, like a TLabel. (Also: TTextControl descends from TControl).
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.
Moving from TBX to SpTBX. I used in the past TTbxDockablePanel which has such props:
DockedWidth
DockedHeight
FloatingWidth
FloatingHeight
I can't find such properties in SpTBX panels, so how should I change my code to use such props? ie. i need to get/set SpTBX panel's docked width/height and floating width/height.
DockedWidth and DockedHeight
A TSpTBXDockablePanel now has a property DefaultDockedSize. A docked panel is docked to either a vertical or horizontal dock, so it only needs one size, which specifies the width (in a vertical dock) or height (in a horizontal dock.) The length of the other axis is a result of either the dock size or the other panels in the same dock. If there are other panels, the size it becomes is the width of the other panels in the dock. If there aren't, it will use either the previous size (if DefaultDockedSize is 0) or try to use DefaultDockedSize.
See TSpTBXCustomDockablePanel.SetParent for the code. You'll be interested in the two branches beginning if ToDock then... and if ToFloating then.... There are some comments there that I've tried to interpret to write the above.
From memory, when I converted from TBX to SpTBX years ago, this was the hardest area to get behaving exactly the same. However, you can get it to behave 'okay', ie with behaviour that makes sense, easily.
FloatingWidth and FloatingHeight
Replaced by FloatingClientWidth and FloatingClientHeight. Note that these are the client sizes not window sizes, but in general they should be direct replacements.
In addition
There is a comment at the top of the SpTBXDkPanels.pas file,
// - To handle the size constraints use GetMinMaxSize when the DP is floating,
// and ConstrainedResize when is Docked (explicitly check if it's docked).
You might find that useful too.
There are a reasonable number of comments scattered through the code. The SpTBX library doesn't have very good documentation, but it does come with high-quality source... Use the source, Luke :)
On my notebook with a screen resolution of 1280x800 I've developed an application. Now I want to use it on a desktop computer with a resolution of 1600x1200.
Of course, it's too small on the desktop computer. I've set the sizes so that I could see the whole form on my notebook. But on the desktop computer, everything should be resized.
But on the large screen, things shouldn't be viewed bigger which means that the same amount of information can be displayed. Things should get a higher height and width value so that more information can be displayed.
In complicated code I mean something like this which should run automatically once when the form is created (OnCreate):
devResolutionX := 1280;
devResolutionY := 800;
useResolutionX := 1600; // how to get / read out this property?
useResolutionY := 1200; // how to get / read out this property?
Form1.Height := Form1.Height+devResolutionY-useResolutionY;
Form1.Height := Form1.Width+devResolutionX-useResolutionX;
// do that with all components which makes this approach complicated
What must I work with to reach that goal?
ScaleBy
alignments
anchors
Thank you very much in advance!
It looks like you just need to set the BorderStyle property of your form to bsSizeable. This will allow the user to resize the form (or maximize it) as he sees fit.
You will also want to make use of anchors here. If you set the akLeft, akTop, akRight, and akBottom anchors for all the components on your form, they will resize with the form.
As soon as you do this, though, you will probably quickly realize that wasn't actually what you wanted to do after all. These growing components are probably going to overlap with each other. So, you are going to need to put some thought into which edges of which components get anchored and which don't.
Sometimes you will need to do some more complicated component moving and sizing than can be handled by anchors alone. In these cases, you will want to handle the Form's OnResize event. This event will get fired whenever the user resizes the form, and it will give you the chance to do some math to recalulate the sizes and positions of certain components.
Just set your anchors correctly and the additional info will show. I wouldn't recommend programmatically forcing an arbitrary height and width. The best thing to do is use the form's OnClose event to save the form's height and width and then set the height and width with OnCreate.
Please have a look at this screenshot
alt text http://www.maclife.com/files/u18/Yep3-big.jpg
I think these are the main features of such a 'tag panel':
1) Each tag on the panel is a standalone control and can be clicked
2) Auto line wrapping when there is not enough space to show the next tag in the current line.
3) Rounded corner rectangle border for each tag is a nice-to-have feature.
I want to implement the similar function in Delphi, Is there an existing control to do this? If not, what's the best way to implement such a control?
Thank you.
When you are on a recent Delphi version use a TFlowPanel and some appropriate controls for the tags. A simple TButton or a TLinkLabel should do for that.
Each clickable tag doesn't necessarily have to be its own control. It just has to be a region that you can detect being clicked.
Suppose you represent each area as a Windows region. You can figure out how wide each one should be based on its text with the TCanvas.TextExtent function. Then create a region with a function like CreateRectRgn. For rounded corners, try CreateRoundRectRgn instead. You can test for mouse events in each region with the PtInRegion function. You can paint borders around them with FrameRgn. The last obstacle is to draw them on the screen so they'll all fit. You're creating the regions and you know their widths, so assign tags to a row until you run out of space, and then start the next line.
There are two possible solutions to custom alignment in Delphi 7. You can make your own flowpanel by deriving from TCustomPanel and override the AlignControls( )-method, or you can set alignment to alCustom and handle the OnAlignPosition-event.
I guess I would have gone for the TCustomPanel-derivative option. TFlowPanel in form Delphi 2007 uses that option- I have to admit, though, that I have never tried either my self...
How to change at runtime by code (not for groupskintype), the skin type for a sptbxtoolbar component?
You can only change the skin of all SpTBXLib components at once.
Use this code
SkinManager.SetSkin('Office 2007 Blue');
You can however set for each SpTBXLib component if it is drawed using the skin, Windows look or the default look, by setting assigning the SkinType property.
MyComponent.SkinType := sknWindows;
Hint: Toolbars itself do not have the SkinType property. They are always drawn using the skin.
I don't know that component, but found this with Google. Hope it helps.