开发者

Delphi - Duplicate tpanel and tbuttons on second form

开发者 https://www.devze.com 2022-12-19 02:55 出处:网络
On my main form I have a TPanel containing buttons that act as a toolbar.I want to clone/copy this toolbar and the buttons and their functionality to a second form.

On my main form I have a TPanel containing buttons that act as a toolbar. I want to clone/copy this toolbar and the buttons and their functionality to a second form.

Cloning the menu was simple using newmenu.merge(mainmenu). That was an excellent shortcut to duplicating a Tmainmenu.

But I am at a loss on how 开发者_JS百科to easily duplicate my toolbar without having to manually assign the events and keep a timer to compare and track which buttons are enabled and disabled in comparison to the real mainmenu on the main form. Depending on what the application is doing the main toolbar buttons will be enabled and disabled at various times.

Any ideas here? Thanks for any suggestions or tips to make this easier.


  • Duplicating the controls

    In the Form Designer, select the panel and press Ctrl+C to copy it and all its children to the clipboard. Go to the second form and press Ctrl+V to paste.

    If you're still working on the design and want to keep it consistent between both forms, then create a TFrame and design your toolbar layout there. Then put an instance of that frame on both your forms. Changes to the frame design will be reflected in the forms.

    See Working with frames in the help.

  • Making sure both sets of buttons are enabled consistently

    Create a data module. Put a TActionList on it. Add an action to it for each button on your main form. Assign event handlers to the actions' OnUpdate events. In them, set the actions' Enabled properties. Finally, assign each button's Action property to refer to the corresponding action object. The buttons will automatically get enabled and disabled with the actions. No timer required.

    Furthermore, you can handle the actions' OnExecute events, too. Clear each button's OnClick property, and then move the button's OnClick code into the corresponding action's OnExecute handler. It will automatically get called when you click the button, even though the OnClick property is empty.

    When you assign the Caption or Hint property of a TAction, the corresponding properties of any associated controls also change. Likewise for images, if the control supports them. Actions can be assigned to menu items, too.

    See Using action lists in the help.

  • Acting like a toolbar

    Just use TToolbar. That's what it's for.

    Or, once you're used to actions, put a TActionManager in your project and use it with TActionToolbar and TActionMainMenuBar. See Organizing actions for toolbars and menus in the help.


Are the buttons attached to actions? If so, you can use the OnUpdate event of the TActionList to specify what should and should not be enabled. If not, it isn't too much work to convert to using actions.

If you go this route to convert to using a ActionList, consider putting the ActionList in a datamodule where different units and forms could reference it.


You can Use ClipBoard Object For Copy Your Panel.

Clipboard.SetComponent(Panel1);
Clipboard.GetComponent(Form2,GroupBox1);

0

精彩评论

暂无评论...
验证码 换一张
取 消