2

I build an winforms application in c#.

I'm trying to change the default icons of MSAGL GViewer component:

MSAGL icons

but I don't find where to do that.

How can I change them?

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
Cuzi
  • 1,026
  • 10
  • 16

1 Answers1

3

GViewer control uses an old ToolBar control to show those buttons. To replace those icons, you can find the toolbar in controls collection of the viewer control and set a new ImageList containing new images for the toolbar:

var toolbar = this.gViewer.Controls["toolbar"] as ToolBar;
toolbar.ImageList = this.imageList1;

The image list should have 18 images in below order. When adding images to image list. After adding images, set the Name property of image at index 2 to zoom.bmp because the toolbar use it's name instead of index:

enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

Using above images, and ColorDepth set to Depth24Bit and TransparentColor set to Magenta here is the final result:

enter image description here

Also as another option you can set ToolBarIsVisible property of GViewer component to false and use your own ToolStrip or ToolBar. Then when clicking each button, you can call corresponding method of viewer component, like ZoomInPressed, ZoomOutPressed, BackwardButtonPressed, ForwardButtonPressed, ... .

Note:

For more information you can take a look at Microsoft Automatic Graph Layout source code repository and source code for GViewer control.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • The solution is completely tested and works properly. Do you have any problem applying the answer? Let me know if you have any question about answer or if you find it helpful. Waiting to hear from you :) – Reza Aghaei Jun 17 '16 at 02:56
  • By some reason the icon on index 3 is not appear: https://s32.postimg.org/8f3rtkpud/Capture.png – Cuzi Jul 06 '16 at 18:08
  • Probably you didn't see this part of the answer: *When adding images to image list, set the name of image at index 2 to zoom.bmp because the toolbar use it's name insetead of index*. After adding the images in the specified order, for image at index 2 of imagelist, set name to `zoom.bmp`. – Reza Aghaei Jul 06 '16 at 19:02
  • Actually I saw that part this how my list look a like: https://s32.postimg.org/4ca0ehnb9/Captur2e.png – Cuzi Jul 06 '16 at 19:08
  • Let me check, maybe I wrote it wrong, the screenshot is taken from a working sample. I'll check it in a minute... – Reza Aghaei Jul 06 '16 at 19:09
  • Everything is OK, so to make sure you are setting the value correctly, Open `Images` collection editor of `ImageList`, click on image at index 2, make sure in the propertygrid, in front of `Name` property the value is `zoom.bmp` – Reza Aghaei Jul 06 '16 at 19:12
  • Yes it is like that: https://s32.postimg.org/lx6lqz96d/zoomislikethat.png – Cuzi Jul 06 '16 at 19:20
  • Oops, the mistake is here. You should change item at index 2. Indexes are zero based, you should change the name of item at index not 0, not 1, but **2**, in fact 3rd item. – Reza Aghaei Jul 06 '16 at 19:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/116607/discussion-between-cuzi-and-reza-aghaei). – Cuzi Jul 06 '16 at 19:27