Page 1 of 1
Commander button in VS2005
Posted: Tue Feb 14, 2006 10:02 pm
by 9637570
I'm updating an application from VS 2003 to 2005, and I have code where I add some buttons to a commander. The buttons are there, and work, but only part of the icons is appearing. It's as if I have a very thin button. Any idea why this is happening?
This is an example of how a button is created
System::Windows::Forms::ToolBarButton ^newButton = gcnew System::Windows::Forms::ToolBarButton();
newButton->ToolTipText = "Add/Edit the plot info";
commander1->ImageList->Images->Add(form1ButtonList->Images[0]);
newButton->ImageIndex = commander1->ImageList->Images->Count -1;
newButtons[13] = newButton;
Posted: Wed Feb 15, 2006 11:39 am
by narcis
Hi sring,
The commander is based on a System.Windows.Forms.ToolBar. Can you successfully add buttons to an instance of this class?
Posted: Wed Feb 15, 2006 3:48 pm
by 9637570
Yes, the buttons are there, just partly hidden, it's like there is something in front of them. I have been through all of the components on the form and there doesn't seem to be anything that could account for it. The first extra button, you can see the entire left edge of the image as well as its top. The other buttons, just the top. It's as if there was a rectangle laid over most of the buttons. If you want, I can send you a jpg so that you can see what I mean.
Posted: Wed Feb 15, 2006 3:59 pm
by narcis
Hi sring,
Yes please, post the image at news://
www.steema.net/steema.public.attachments newsgroup.
Posted: Wed Feb 15, 2006 4:30 pm
by 9637570
The image has been posted
Posted: Thu Feb 16, 2006 10:58 am
by Marc
Hello,
The cause is most likely the Label used to display Commander information (eg. Rotation and Elevation). The Label is private, we'll improve access to it for an upcoming release.
For the moment you could hide it:
eg. (There's only one Label on the Commander)
Code: Select all
foreach (object o in commander1.Controls)
{ if (o is Label)
((Label)o).Visible=false;
}
Regards,
Marc Meumann
Posted: Thu Feb 16, 2006 5:00 pm
by 9637570
That fixed it
Posted: Thu Feb 16, 2006 5:34 pm
by 9637570
But, I'm still having a slight problem. The third button that I add always comes out as a black square. I've switched icons back and forth with the fourth button, so I know that the icon can display correctly. Any idea why this would be happening?
Posted: Fri Feb 17, 2006 12:14 pm
by Marc
Hello,
If I run a test using one of the images already in the list (ie. the '3D' image) to add 5 buttons all the images come out ok. You might like to confirm that:
eg.
Code: Select all
for (int i = 0; i < 5; i++)
{
System.Windows.Forms.ToolBarButton newButton = new System.Windows.Forms.ToolBarButton();
newButton.ToolTipText = "My text";
newButton.ImageIndex = commander1.ImageList.Images.Count - 5;
((ToolBar)commander1).Buttons.Add(newButton);
}
Using a new ImageList as per your example, it checks out in the following way:
Code: Select all
for (int i = 0; i < 5; i++)
{
System.Windows.Forms.ToolBarButton newButton = new System.Windows.Forms.ToolBarButton();
commander1.ImageList.Images.Add(myImageList.Images[i]);
newButton.ToolTipText = "my text";
newButton.ImageIndex = commander1.ImageList.Images.Count - 1;
((ToolBar)commander1).Buttons.Add(newButton);
}
Please note that the Commander Image colours are 25x25px, Depth8Bit. In the ImageList I used the colours were 32Bit and colour 'downsizing' takes place. .. I wouldn't think that would have an effect on your image's appearance as it would have moved when you interchanged the icons, but worth bearing in mind. See if a loop similar to the one above gives the same results.
Regards,
Marc Meumann
Posted: Fri Feb 17, 2006 5:53 pm
by 9637570
If I do your first loop, adding in your 3D button 5 times, they all look ok.
When I tried the second loop, the third button comes out black. So, I changed it so that I was inserting my 0 icon 5 times. And, the third one still comes out black, but the other 4 show the 0 icon fine.
Posted: Fri Feb 17, 2006 6:20 pm
by 9637570
This has something to do with setting the ImageIndex.
If, in the second loop, I keep the index at the first button I add, they all look good. If I let the index increment, even if I just do it manually and don't make it depend on the count, and even if I'm adding the same icon 5 times, the third one comes out black.
Posted: Mon Feb 20, 2006 3:25 pm
by Marc
Hello,
Interesting. That's different to the behaviour in tests here. I wonder if it has anything to do with the programming language.
Is that a useable workaround if you assign a different image to the 'fixed' index? If there's anythiing further we can try please let us know.
Regards,
Marc Meumann