So I made my own button from a Rectangle with a MouseEnter, MouseExit and MouseUp Event and a text label on top of it which has a MouseDown and MouseUp Event. The events give the button a specific fill colour and the label Events are triggering an action. Now, is there a way to create a Class from this button/label combination which includes all the Events so I can create them faster the next times?
Put all these components into a DesktopContainer. Then you have it.
Sounds messy. It may be better to recreate the original button by painting into a canvas control.
I support the motion.
But you are both criticising how the button is put together, rather than answering the OP’s question.
Yes.
But you can do it now.
Thanks Tim, I have spent quit some time on figuring out how to create the button and would like to keep it a is. Your answer is helpful. I wanted a button with a white text which I could not get done with a normal button, that is why I ended up using a rectangle object and continued from there.
Have you looked at the documentation, especially there:
The thing about the DesktopContainer, is that if you decide to alter the button later, you only need do it in one place.
Your new container will appear in the Project Controls area of the Library pane in the IDE. You can drag it from there to your layout to make a new button.
OR, instead:
You can say, in code:
Var ptr as myButton
ptr = new myButton
which will make a new button exist in this universe but it won’t (yet) be on your layout. To add it to the layout you need to do like:
ptr.EmbedWithin (self)
and the button appears on the layout. You then have to set Top and Left to position it.
You can do either or both - depends on your needs.
Here is btw what I created, took me a while to get all the coding correct. Mouse over a button changes the colour, pressing a button gives it a sticky green colour which does not change with the mouse over as long as the screen is visible that the button press opened.
Thanks Tim, I will go for the DesktopContainer option.
Very nice button.
I think that may be a bit of overkill… For such things I have just used a canvas subclass in the past.
-Karen
Here’s the Events from a Canvas button:
Same here.
I used an Emoji as the image / a Text (large E character) painted above to say it’s an Edit button.
And people can do better.