Come personalizzare la ToolBar?

Forum dedicato ai programmatori di X# in lingua italiana – Italian language forum

Moderator: wriedmann

Post Reply
veliero
Posts: 22
Joined: Sun Feb 25, 2018 11:28 pm

Come personalizzare la ToolBar?

Post by veliero »

Salve a tutti,
ho visto che in ambiente XIDE (come già avveniva in VO) è possibile utilizzare il VOMenuEditor per creare un proprio menù da associare alle finestre e che modificando la proprietà "Toolbar style" viene generata automaticamente la ToolBar relativa al menù. Volevo, se possibile, qualche esempio di come poter personalizzare questa ToolBar usando le mie icone senza dovermi accontentare di quelle standard.
Ho provato ad aggiungere le mie icone come "resources" in un applicazione VO/X# di prova:
Cattura 1.JPG
Cattura 1.JPG (27.9 KiB) Viewed 1914 times
e questo è il risultato in XIDE:
Cattura 2.JPG
Cattura 2.JPG (19.2 KiB) Viewed 1914 times
Ho definito due icone (clienti.ico e impostazioni.ico) ma non so come poterle usare poi nella ToolBar.
Qualcuno ha già (sicuramente) affrontato il problema?

Saluti
Francesco
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Come personalizzare la ToolBar?

Post by Chris »

Hi Francesco,

Unfortunately this is a bit more complicated, here's what you need to do:

1. First create a big bitmap that contains all the icons for your menu. You can start with the standard toolbar bitmap that is used by default in VO and X# and you can find it in C:cavo28VolibGUicavotb.bmp. So you can copy this file and add new bitmaps to it, or replace some that it already has. You can also delete some if you want. Then save the new bitmap somewhere in your disk, for example in C:BMPMyNewToolbar.bmp

2. Create and add in your XIDE app a native resource (.rc) file containing this:

MyNewToolbar BITMAP c:BMPMyNewToolbar.bmp
(note, the double are important)

3. Go to the menu editor for your menu, select the main menu item and in the Properties window, set the Properties:

Ribbon = MyNewToolbar
(this is the class name you used above)
RibbonFilename = C:BMPMyNewToolbar.bmp

Now save the menu and go to each menu item that you want to use a toolbar bitmap, click on the property "Button Bmp", now XIDE must show you a list of available bitmaps, taken from your big bitmap. Select the ones you want, save and run, the bitmaps should now appear in the toolbar.

If anything is not working as described above, please tell me and I will send you a complete test app.

.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
veliero
Posts: 22
Joined: Sun Feb 25, 2018 11:28 pm

Come personalizzare la ToolBar?

Post by veliero »

Ciao Chris,
grazie per le info. Ho seguito tutti i tuoi passi che erano riportati chiaramente:

1) sono partito da una nuova BITMAP TOOLBAR con altezza 32 punti (invece di 16) che ho chiamato MiaToolbar.BMP

2) ho aggiunto il file risorsa (MIATOOLBAR.RC) contenente la definizione:
MiaToolbar BITMAP "c:XIDEPROJECTSPROGETTI BASEAPPLICATIONSGESCAF100RESOURCESMiaToolbar.bmp"
(nota che ho dovuto racchiudere il percorso del file tra doppio apice "" altrimenti non localizzava il file BMP)

3) ho editato le proprietà del menù: Ribbon -> MiaToolbar
RibbonFileName -> C:XIDE... ...RESOURCEMIATOOLBAR.BMP

4) ho salvato e compilato senza errori

5) ho editato una voce di menù assegnando la proprietà Button BMP (l'icona appariva ritagliata 16x16 e non 32x32 come desideravo) e l'ho comunque assegnata

6) ho lanciato la compilazione e mi ha dato il messaggio di errore alla riga:
oTB:Bitmap := MiaToolbar{}
con il messaggio:
error XS0246: The type or namespace name 'MiaToolbar' could not be found (are you missing a using directive or an assembly reference?)

Pensi di poter capire dove sbaglio?

Saluti
Francesco
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Come personalizzare la ToolBar?

Post by Chris »

Hi Francesco,

Oops, sorry, I forgot to include the bitmap class declaration. You need to add also this:

Code: Select all

CLASS MiaToolbar INHERIT Bitmap
CONSTRUCTOR(kLoadoption, iWidth, iHeight)
	SUPER(ResourceID{"MiaToolbar", _GetInst()},kLoadoption, iWidth, iHeight)
END CLASS

Not sure how to use different sized toolbar bitmaps, had never done this before. Please let me look into it and will get back to you!

.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Come personalizzare la ToolBar?

Post by Chris »

Hi Francesco,

For using 32x32 pixel bitmaps, you need to add (manually) this line, after the instantiation of the toolbar:

oTB:Bitmap := MiaToolbar{}
oTB:ButtonSize := Dimension {32,32} // <---add this

now it should all work. Of course the above line will be deleted the next time you edit the menu in the editor, but I will make XIDE automatically insert it, by reading and using the height of the large toolbar bitmap used.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Come personalizzare la ToolBar?

Post by robert »

Chris, Fransesco,

I would subclass the ToolBar class and set the button size in the subclassed constructor.
That way, you do not have to worry about code that gets overwritten.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Come personalizzare la ToolBar?

Post by Chris »

Robert,

Good idea of course!
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
veliero
Posts: 22
Joined: Sun Feb 25, 2018 11:28 pm

Come personalizzare la ToolBar?

Post by veliero »

Grazie Chris, ora la compilazione va a buon file e la ToolBar funziona bene.
Per favore Robert puoi mostrarmi come eseguire il SUBCLASS della classe Toolbar per non dover aggiungere manualmente ogni volta la riga:
oTB:ButtonSize := Dimension {32,32}

Grazie per la vostra disponibilità.

Saluti
Francesco
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Come personalizzare la ToolBar?

Post by Chris »

Hi Francesco,

Something like this:

Code: Select all

CLASS Toolbar_32x32 INHERIT ToolBar
	CONSTRUCTOR(oOwner,xID,oPoint,oDimension,lEnableBAnds)
		SUPER(oOwner,xID,oPoint,oDimension,lEnableBAnds)
		SELF:ButtonSize := Dimension {32,32}
	RETURN
END CLASS
And then, in the menu editor, select the main menu item and set the property "Toolbar Inherit from" to Toolbar_32x32. That should do it!

.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
veliero
Posts: 22
Joined: Sun Feb 25, 2018 11:28 pm

Come personalizzare la ToolBar?

Post by veliero »

Grazie Chris,
funziona benissimo. Grazie anche a Robert.

Saluti
Francesco
Post Reply