The VCL components in C++Builder have a context menu: Postion | Align | Horizontal | CenterInWindow; I am creating VCL components dynamically at run time. How can I set this menu dynamically using code?
You can't invoke that menu item, as it doesn't exist at runtime. It is a feature of the IDE's Form Designer.
All you can do at runtime is set each control's Left/Top properties as needed, ie:
Control = new TWhatever(...);
Control->Parent = ...;
Control->Left = (Control->Parent->Width - Control->Width) / 2;
Control->Height = (Control->Parent->Height - Control->Hieght) / 2;
Adjust as needed if you need to position multiple controls.
Related
I am working on a project using Delphi where I am making rows and columns for a GridPanel dynamically. I am also creating a panel (TPanel) that I intend to place in each cell dynamically.
My question is: How do you assign the newly created panel to a particular cell that is in the GridPanel?
I am guessing that I have to assign the panel's "Parent" property so that it is the GridView. However, I have not been able to adjust a "Row" or "Column" property for the TPanel unlike when you able to when you assign a panel to the GridPanel using the design environment.
How do you assign the newly created panel to a particular cell that is
in the GridPanel?
The answer is, you can't. Adding new components to the TGridPanel, wether at design time or programmatically, places the new component in the next unoccupied cell. By default, in left to right order.
The ExpandStyle property (emAddRows or emAddColumns) determines how the TPanelGrid is expanded when filled, and further controls are added.
After you have added the new panel (or other component) to the TGridPanel you may change it's position as others have answered, by accessing the control via the ControlCollection property.
Use:
TGridPanelLayout.ControlCollection[position].row := 0;
You can access the property
TGridPanelLayout.ControlCollection[index].row := 0;
and
TGridPanelLayout.ControlCollection[index].Column := 0;
I've created a style with the Bitmap Style Designer for Delphi XE7.
I've updated the button style to white with a blue border and duplicated it to create an orange button called Button_Copy.
I've exported the style to FireMonkey, but I can't find Button_Copy to assign it to a button on my form. How do I do this?
Also, can I rename Button_Copy to e.g. OrangeButton?
In the Bitmap Style Designer, save the style as a FireMonkey style.
Add a TStyleBook to your form.
Set the StyleBook property to the stylebook.
Double-Click the StyleBook and open your style. Close and Apply.
You can now set the StyleLookup property of a button to Button_Copy and if all is well you will see your new style.
Note that your new style won't appear in the selection list for StyleLookup - the list of available values appears to be hard coded.
And, of course you can change the name - just change the StyleName property of the top level object (probably a TLayout). The normalnaming convention is to append the word 'style', e.g. OrangeButtonStyle.
I have a TComboBox with several Strings in its Items list. When run on Windows, this works properly - I am able to click the combo-box, have the items appear, and then select one of the items.
When I set the OS target to OS X, however, the TComboBox does not allow me to select an item. I can click the TComboBox and have the items appear, but when I try to click an item from the drop-down list I receive a 'bump' sound on the Mac, and nothing is selected.
How can I get TComboBoxes to work properly on the Mac using Firemonkey?
I am using C++ Builder XE6 with FMX (Firemonkey).
Workaround:
Basic idea: use Show () instead of ShowModal (), combined with a component that will make the main form non-clickable while the child form is shown.
On the main form, add a TRectangle (or TPanel) with Visibility = false, Opacity = 0.25 (or something like that - could also be 0), and HitTest = true.
Then, when about to show a child form, call a function that sets the TRectangle on the main form to cover the main form (setting its Position->X, Position->Y, Width, Height) and then sets its Visibility = true.
Then, call a child form with Show () instead of ShowModal ().
When the child form is done, call a function on the main form that sets the TRectangle back to Visibility = false.
I have a added components on a form object dynamically
Edit1 := TEdit.Create(form3);
I have got the object form3 of Tform class. Now what i want to do is I want to create a component template of form3 so that I can just drag and drop that component template on any of my other from and all the components present in it will be automatically available for me to use. Can any one help me with how to about doing component template?
From the second part of your question it seems you want to make a reuseable Frame that you can drop at design time on a form, and drag it around. Frames can be dropped multiple times on multiple forms. Changes in the design are reflected in the copies. Create a frame with File > New > Frame (Delphi 7) or File > New > Other > Delphi Projects > Delphi Files > VCL Frame (XE2).
However, if the components therein should also be visible during designing, then you have to create those controls also at designtime. A frame works exactly like a normal form, so there should be no problem there. Controls generated in code will only show up at runtime, which is just fine if you want that.
I have just added a new panel to StatusBar1 and it is called 5 - TStatusPanel. I want to give it a different name but I can't remember how to do this.
I want to rename 5 - TStatusPanel to 5 - GripArea. As you can see from the image I have done this before (see Num, Caps, AM/PM) but I can't remember how I did this. It sucks to get old.
Just change the Text property of the TStatusPanel. This is what is displayed in the status panel editor. Of course, this will make the text visible in the panel! Normally, in code, you access the status panels using the StatusBar1.Panels[PanelIndex] array. PanelIndex is the zero-based index of the panel. I always declare constants such as
STATUS_FILE_POSITION = 0;
STATUS_FILE_SAVED = 1;
STATUS_LONG_TEXT = 2;
STATUS_ZOOM_CONTROL = 3;
and use these to remember the panels. (The code above is from my text editor.)
So I can do, for instance,
StatusBar.Panels[STATUS_FILE_SAVED].Text := 'Modified';
Here's a tip that would have saved some hunting: right-click on the form, View As Text. Now you'll see the form layed out as properties, and you could have found the control, seen how the other panels were named, and fix the last one.
Alt+F12 to toggle the text view on/off.