Print Page | Close Window

CommandBarButton Width

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=7458
Printed Date: 18 June 2025 at 7:30pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CommandBarButton Width
Posted By: apuhjee
Subject: CommandBarButton Width
Date Posted: 26 June 2007 at 5:25pm
At what point is the Width of a RibbonBar button known?  I'm trying to add three "state" buttons and set them all to be the same size as the widest... but the width = 0 immediately after they have been added to a group.
 
Thanks ~ jp



Replies:
Posted By: Oleg
Date Posted: 27 June 2007 at 12:48am

Hi,

Show code you tried.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: apuhjee
Date Posted: 27 June 2007 at 2:08am
This is what it looks like by default:
 
 
 
This is what I'm going for:
 
 
 
Notice the watch value:
 
 
 
And here is the code I'm using.   Note: it looks ok if I uncomment the explicit width values of 60... but I'd rather not assume that the font metrics will always be the same as they are on my dev machine
 

private static void ConfigureViewTag()

{

    RibbonTab tabView = AddTab(ID.ID_TAB_VIEW, "View");

    RibbonGroup groupPanes = AddGroup(tabView.Id, ID.ID_GROUP_PANES, "Panes", false, null);

   

    viewObjectExplorerPane = AddControl(groupPanes.Id, "VIEW_OBJECT_EXPLORER_PANE", XTPControlType.xtpControlButton, "Object Explorer", "Show/Hide the Object Explorer Pane", "ToggleObjectExplorerPaneAction");

    CommandBars.Icons.LoadIcon(Path.Combine(ResourceManager.ResourcePath, "object_explorer.ico"), viewObjectExplorerPane.Id, XtremeCommandBars.XTPImageState.xtpImageNormal);

 

    viewPropertiesPane = AddControl(groupPanes.Id, "VIEW_PROPERTIES_PANE", XTPControlType.xtpControlButton, "Properties", "Show/Hide the Properties Pane", "TogglePropertiesPaneAction");

    CommandBars.Icons.LoadIcon(Path.Combine(ResourceManager.ResourcePath, "properties.ico"), viewPropertiesPane.Id, XtremeCommandBars.XTPImageState.xtpImageNormal);

 

    viewCalendarPane = AddControl(groupPanes.Id, "VIEW_CALENDAR_PANE", XTPControlType.xtpControlButton, "Calendar", "Show/Hide the Calendar Pane", "ToggleCalendarPaneAction");

    CommandBars.Icons.LoadIcon(Path.Combine(ResourceManager.ResourcePath, "calendar.ico"), viewCalendarPane.Id, XtremeCommandBars.XTPImageState.xtpImageNormal);

 

    SetEqualButtonWidth(groupPanes);

 

    //viewObjectExplorerPane.Width = 60;

    //viewPropertiesPane.Width = 60;

    //viewCalendarPane.Width = 60;

}

 

public static void SetEqualButtonWidth(RibbonGroup group)

{

    int maxWidth = 0;

    foreach (CommandBarControl control in group)

    {

        if (control.Width > maxWidth)

            maxWidth = control.Width;

    }

 

    foreach (CommandBarControl control in group)

    {

        control.Width = maxWidth;

    }

}

 

public static CommandBarControl AddControl(int groupId, string resourceName, XTPControlType controlType, string controlCaption, string controlDescription, string actionMethod)

{

    RibbonGroup group = RibbonBar.FindGroup(groupId);

    int resourceId = ResourceManager.AddResource(resourceName);

    CommandBarControl control = group.Add(controlType, resourceId, controlCaption, false, false);

    control.Action.Tag = actionMethod;

    CommandBars.Actions.Add(resourceId, controlCaption, controlCaption, controlDescription, group.Caption);

 

    return control;

}

 

 


Posted By: apuhjee
Date Posted: 27 June 2007 at 2:21am
While we're on the topic (sort of...), it would be extremely awesome if you guys would make a true state button rather than require the use of the Checked property.
 
It may not have been a problem in the past, but with the animation in the Ribbon Bar, the short time between the user click and setting the Button.Checked property looks a little strange.
 
But I'm a perfectionist.  
 


Posted By: Oleg
Date Posted: 27 June 2007 at 4:05am
Hi,
Before it become visible Width will be 0. you can set Width parameter to some predefined value.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: apuhjee
Date Posted: 27 June 2007 at 4:08pm
Very interesting. So I have to display it to the user first - then change its visual appearance.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net