Ticket Q492142
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

WinForms - How to customize ActionContainerViewItem's Action height and width

Customize ButtonSize for ActionViewController in DetailView

created 12 years ago

Hello dear Supporters,
i would like to change the size of the buttons which are assoziated with some actions
which i inserted in a ViewController and the according DetailView
public partial class WinCustomizeActionButtonsViewController : ViewController
    {
        public WinCustomizeActionButtonsViewController()
        {
            InitializeComponent();
            RegisterActions(components);
            TargetObjectType = typeof(Pruefung);
        }
        protected override void OnActivated()
        {
            base.OnActivated();
            foreach (WinActionContainerViewItem item in ((DetailView)View).GetItems<WinActionContainerViewItem>())
            {
                if (item.Id == "CertWPSActions")
                {
                    item.ControlCreated += item_ControlCreated;
                    IModelActionContainerViewItem q = (item.Model as IModelActionContainerViewItem);
                }
            }
        }
        private void item_ControlCreated(object sender, EventArgs e)
        {
            ((ButtonsContainer)((ViewItem)(sender)).Control).ActionItemAdding += CustomizeWinActionContainerViewItemController_ActionItemAdding;
            ((ButtonsContainer)((ViewItem)(sender)).Control).SizeConstraints = SizeConstraints.None;
        }
        void CustomizeWinActionContainerViewItemController_ActionItemAdding(object sender, ActionItemEventArgs e)
        {
            if (e.Item.Action.Id.Contains("WPS"))
            {
                SimpleButton button = (((ButtonsContainersSimpleActionItem)e.Item).Control) as SimpleButton;
                if (button != null)
                {
                    if (!string.IsNullOrEmpty(e.Item.Action.Model.ImageName))
                        button.Image = ImageLoader.Instance.GetSmallImageInfo(e.Item.Action.Model.ImageName).Image;
                    //button.Font = new Font(button.Font, FontStyle.Bold);
                    //(sender as ButtonsContainer).Con
                    button.Width = 40;
The Size of the button is not changeable…

//(e.Item.LayoutView as LayoutControlItem).SizeConstraintsType = SizeConstraintsType.Custom;
                }
            }
        }
Is anybody able to give me a hint for that?
Your Thomas

Comments (1)
TV TV
Thomas Vetterling 12 years ago

    I think that is a problem with the LayoutControl which is used to 'show' WinActionContainerViewItem…
    It seems not trival to find a 'Setting' to be able to control the button size in a Layoutcontrol.
    Thomas

    Answers approved by DevExpress Support

    created 12 years ago (modified 11 years ago)

    Hello Thomas,
    The following code worked fine in my tests:

    C#
    using System; using System.Drawing; using DevExpress.ExpressApp; using DevExpress.XtraEditors; using FeatureCenter.Module.Actions; using DevExpress.ExpressApp.Templates; using DevExpress.ExpressApp.Win.Editors; using DevExpress.ExpressApp.Win.Templates.ActionContainers; namespace FeatureCenter.Module.Win { public class CustomizeWinActionContainerViewItemController : ViewController<DetailView> { public CustomizeWinActionContainerViewItemController() { TargetObjectType = typeof(DetailViewActionsObject); } protected override void OnActivated() { base.OnActivated(); foreach(WinActionContainerViewItem item in View.GetItems<WinActionContainerViewItem>()) { if(item.Id == "DetailViewActions") { item.ControlCreated += item_ControlCreated; } } } protected override void OnDeactivated() { foreach(WinActionContainerViewItem item in View.GetItems<WinActionContainerViewItem>()) { if(item.Id == "DetailViewActions") { item.ControlCreated -= item_ControlCreated; } } base.OnDeactivated(); } private void item_ControlCreated(object sender, EventArgs e) { foreach(ActionBaseItem actionBaseItem in ((WinActionContainerViewItem)sender).Container.ActionItems.Values) { if(actionBaseItem.Action.Id == "SimpleAction") { ButtonsContainersSimpleActionItem buttonItem = actionBaseItem as ButtonsContainersSimpleActionItem; if(buttonItem != null) { SimpleButton button = buttonItem.Control as SimpleButton; if(button != null) { button.MinimumSize = new Size(300, 0); } } } } } } }

    I hope this helps.

      Show previous comments (2)

        Now, I can't use:
        View.GetItems<WinActionContainerViewItem>()Please tell me the alternative method.
        Thank.

          And I use the Simple Action.
          Thank

          Dennis Garavsky (DevExpress) 9 years ago

            @Dunah: I've created a separate ticket on your behalf (T379400: Problems applying a solution from Q492142). It has been placed in our processing queue and will be answered shortly.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.