Custom Push Button

I’m working within canvas and have been able to make the custom icons appear but I’m struggling with making them a custom push button.

I’m new with XOJO so my learning curve it quite high.

I know there is a mouse down and mouse up event that I can use to make the button but need some starter suggestions or code examples.

Any help would be great.


In the Mousedown event you put:

return true

In the Mouseup event you can add any code what you normally would add in the Action event of a native button.

There are a few resources that might help your learning curve!

First if you’ve never programmed before (or if you’ve kind of made it up as you went along like I did for a while), the Introduction to Programming textbook will help you grasp the foundations of programming.

Then, there’s the user guide. It comes in four books on, you’ll see it in the bottom left corner on the main page. It also comes in handy iBook format so you can have it open on your iPad while you learn!

If you’re doing one icon per canvas, you can use the MouseUp event. That’s how buttons are done, the user only wants to click your button if they let the mouse up on it. If they made a mistake, they’ll drag the mouse off your button, and mouse up there. Using MouseDown they’d be stuck with the function the moment they mousedown’d. You must return true in MouseDown to use MouseUp though.

If you’re using more than one icon on the canvas, you’ll have to track where the mouse is and determine which icon was clicked before acting upon the click.

My personal recommendation though, is to not use custom elements. Apple and Microsoft hire people specifically to design interfaces. I always ask myself when making a custom element, “is this really better than someone who’s job it is to design this?” The answer is usually no, because I’m not making a living designing; and they are…

see here Forum 46028

Take a look at the example that comes with Xojo:

Examples/Desktop/Custom Controls/CanvasButton