2009-10-05 4 views
1

Je ne me suis pas soucié des panneaux, de l'ancrage ou des ancrages. J'ai simplement jeté ensemble un contrôle ToolBar (pas ToolStrip) et semble incapable de le dimensionner.Comment redimensionner un System.Windows.Forms.ToolBar?

System.Windows.Forms.ToolBar tb = new System.Windows.Forms.ToolBar(); 

// Reports 292x28 (approx) if I check width and height 
// Basically the width of the form and I assume a default height 
tb.Size = new System.Drawing.Size(195, 48); 


// Reports 48x48, but does not actually create buttons of that size 
// (It reports 48x48 because I'm retrieving 48x48 icons from a ResourceManager (resx)) 
tb.ButtonSize = new System.Drawing.Size(48, 48); // 

Le plus proche chose que je trouve à faire mon plus grand ToolBar était:

http://bytes.com/topic/c-sharp/answers/241614-changing-height-toolbar-button

Bien qu'il soit plutôt daté. Et je ne l'ai pas compris. Les ToolBarButtons n'ont pas de propriétés Height, Width ou Size. J'utilise SharpDevelop, codant complètement à la main sur Vista, avec tous les frameworks .NET.

EDIT:

Voici le code EXACT que je suis actuellement en utilisant.

#region ImageList/Toolbar 
ImageList toolbarImages = new ImageList(); 
Image wizardToolbarImage = (Bitmap) rm.GetObject("wizard"); 
Image optionsToolbarImage = (Bitmap) rm.GetObject("configure"); 
toolbarImages.Images.Add(wizardToolbarImage); 
toolbarImages.Images.Add(optionsToolbarImage);  

ToolBar toolbarMain = new ToolBar(); 
toolbarMain.Size = new Size(195, 25); // no effect 
ToolBarButton wizardToolbarButton = new ToolBarButton(); 
ToolBarButton optionsToolbarButton = new ToolBarButton(); 
wizardToolbarButton.ImageIndex = 0; 
wizardToolbarButton.ToolTipText = "Wizard!"; 
optionsToolbarButton.ImageIndex = 1; 
optionsToolbarButton.ToolTipText = "Options!"; 
toolbarMain.Buttons.Add(wizardToolbarButton); 
toolbarMain.Buttons.Add(optionsToolbarButton); 

toolbarMain.Appearance = ToolBarAppearance.Normal; 
toolbarMain.ButtonSize = new System.Drawing.Size(48, 48); // no effect 
toolbarMain.ImageList = toolbarImages; 
toolbarMain.ButtonClick += new ToolBarButtonClickEventHandler(toolbarMain_Click); 

Controls.Add(toolbarMain); 
#endregion 
+0

Serait-il possible pour vous de me donner un exemple de code pour la comparaison alors? Comme c'est, les miens sont BEAUCOUP plus petit que 48x48. Je vais ajouter un peu plus du code à l'original pour illustrer tout ce que je fais. – Brainsick

Répondre

1

Dans presque toutes les applications WinForms j'ai écrit, quelle que soit la langue ou le cadre, la barre d'outils ne pouvait être plus haute en utilisant des icônes plus grandes.

+0

+1. C'est aussi mon expérience. – David

0

Vous pouvez également placer la barre d'outils dans un panneau et définir la propriété Dock de la barre d'outils sur Remplir. Et puis vous pouvez dimensionner le panneau à la taille dont vous avez besoin.

+0

Un 'System.Windows.Forms.ToolBar' n'est pas la même chose qu'un' System.Windows.Forms.ToolStrip'. Veuillez lire attentivement la question. –

+0

@Cody Gray. Tu as raison, ma mauvaise. La solution que j'ai suggéré ne fonctionnera pas pour un System.Windows.Forms.ToolBar. – YWE

Questions connexes