Align a component exactly in the middle of a panel - delphi

I have a TRichEdit and a TButton on a TPanel, which is not aligned in the centre of the panel:
Is there a quicker way to align these components in the centre of the panel, than just by dragging it around and guessing if it is in the centre?
Also, I am using Delphi 2010.
I tried selecting the components and using the alignment options:
But it only aligned the button to the rich edit:

First, you must not select the panel, because that is not involved in this process.
Second, there is another toolbar Position that has a button to center the selected elements inside its parent.
I have no Delphi 2010 at hand, so I cannot provide a screenshot, but both icons look quite similar.

Quickest way for aligning components at design time is by using right-clicking on specific component and then choosing Position->Align from the shown popup menu.
If you want to align your component to the center of the parent then chose Center in window for either horizontal or vertical alignment whichever you need. If you have multiple components selected Delphi will align the whole group to the center of the parent and not each individual component to the center of the parent.
If you want to align one component to the center position of another other component then select the two components first and then right click on the component on which you want your component to be centered on. And now in popup menu select Position->Align and in the opened window chose Centers wither for horizontal or vertical alignment based on what you need.

Related

Delphi Resizing Form messes up components

I created my form and it looks fine in the standard size when ran with the program, however when I maximize the form, the components get messed up. I anchored the components on the left and right, however a giant gap is created in the middle of the form and I don't know how to fix it. When in the 'Design' view of the program, all my components are touching from me trying to fill the middle gap. I tried aligning, anchoring and searched online for a while with no luck. Any clue?
Form in standard size upon running program:
Form in full screen with giant middle gap:
From the form's OnResize event, you can compute the width and left property values for the component to fit the new size. You can adjust the width of components or distribute the distance between components to get the look you want. Or a combination of the two.
It is also possible to put the components on two lines if the form's width becomes too small. Or use a scroll panel so that the user can scroll to see what is not possible to show correctly given the width.
All that requires coding. Parts can be done using panels and align the panels.

Delphi 2010 vertical toolbar

I am using RAD Studio 2010 on Windows 10. Is there any way to create a vertical toolbar for Delphi VCL projects? Something similar to what is shown in the attached picture (right side, top to bottom, on main window):
I need selectable items.This mean changing in back color in clicking or when mouse move over it
You can do this with a TListView. Assign your images to a TImageList, and assign that ImageList to the ListView.LargeImages property. Add an item for each image you want to display using the Items property (or right-click on the ListView and choose New Item from the context menu), assigning the proper caption and imageindex for each item. Make sure the ListView.ViewStyle is set to vsIcon, and the ListView.ItemOptions.AutoArrange is set to True.
Here's a sample of the result of a quick test app with a few random images I added - just a few 32x32 images in the Win10 style, courtesy of Icons8. It shows the highlighted Button 3 item as the mouse pointer is hovering over it.
The only drawback to using the TListView is that if the dialog is sized so that all items in the ListView aren't visible, the ListView will display a vertical scrollbar automatically. You'll want to make sure that you leave enough space for that scrollbar just in case, or restrict your window's MinHeight constraint to prevent it from being resized too small. On the other hand, if you want to display more than one item in each row, it's easily accomodated with the TListView - just widen the control to allow more items per row, and the AutoArrange property will take care of everything.

docking a panel in a frame using delphi

I have an application made with frames.
I have a panel on the frame that I need to work out how to float and dock.
I'm not sure how to accomplish this.
I looked at devexpress docking controls, but they only work with forms.
So I think I need to work out 2 issues.
how to make the panel movable and resizable.
how to add docking logic to a frame?
any help will be appreciated.
1) TPanel movable and resizable
A Panel is always movable inside its container (Form, frame, another panel, scrollbox,...) and resizable. You just have to change its Top, Left, width and height properties. To make it dragable, you need to use MouseDown, MouseMove, MouseUp event, detect and handle the required mouse use to drag.
You can even move the TPanel from its container to another container by changing its Parent property. For example, you can move a panel from a TForm to another TForm. That's what you'll use for making your panel floating.
2) Floating TFrame
You cannot use a TFrame as a floating form. You need a TForm for that.
Note that you can use a TForm much like a TFrame. Use CreateParented to create the form and attach it to a container like a TFrame.

How resize a cxgrid with the mouse?

I have 4 cxgrid into a cxTabSheet, 3 aligned albottom and 1 aligned alClient...
When the mouse is over the edge of any cxgrid, the cursor mouse doesn´t change to the crSize(NS, WE, NESW, NWSE) and cannot select the border of grid for drag the mouse and resize it.
How can I do this?
The easiest way to do this, without writing any code, is to use one or more splitters on your form: see TSplitter and the Devex custom version, TcxSplitter, in the online help.
To use, place one or more splitters on the form orientated to allow resizing of the grid(s) as you wish, then place the grids on the appropriate areas of the splitters, or on panels on the splitters. One splitter can be placed inside another, so that you can have one resizable area inside another.

How to offset the position of the cursor in an edit control?

I'm building a custom edit control which consists of adding both an icon at the left and an icon button at the right, both inside the edit control. This requires shifting the starting point of the text (and cursor) to the right by X amount of pixels. This also means I need to 'Limit' how wide the text can be drawn too, to make room for the button on the right. The intention is to provide both a custom icon on the left, such as in a browser, as well as an 'X' button on the right to clear the contents of the edit control.
How to offset the Rect of where to draw the text and cursor in a TCustomEdit descendant?
If you are using more recent version of Delphi, there should already be a TButtonedEdit Control and can do your work.
If not, I think you can send a EM_SETMARGINS message to your TCustomEdit to set the left and right margin.
SendMessage(CustomEdit.Handle, EM_SETMARGINS, EC_LEFTMARGIN or EC_RIGHTMARGIN, MakeLong(LeftMargin, RightMargin));

Resources