Canvas event

I have two canvas both have 3 states MouseEnter,MouseExit and MouseDown,and one global property as integer for the states.
Tha canvas one have the bellow simple code.
MouseDown

panel1.Value=1 Canvas1State =2 me.Invalidate
MouseEnter

Canvas1State =1 me.Invalidate me.MouseCursor = System.Cursors.FingerPointer
MouseExit

If Canvas1State = 2 Then exit Canvas1State = 0 Me.Invalidate
And the paint event
Select Case Canvas1State

[code]
Case 0
g.ForeColor = &c29344000
g.FillRect(0, 0, Me.Width, Me.Height)
g.TextSize = 14
g.TextFont=“HelveticaNeue-Light”
g.ForeColor = &cFFFFFF00
g.DrawString(“A”, 45, Me.Height / 1.5)

Case 1
g.ForeColor = &cFD771300
g.FillRect(0, 0, Me.Width, Me.Height)
g.TextSize = 14
g.TextFont=“HelveticaNeue-Light”
g.ForeColor = &cFFFFFF00
g.DrawString(“B”, 45, Me.Height / 1.5)

Case 2
g.ForeColor = &cFD771300
g.FillRect(0, 0, Me.Width, Me.Height)
g.TextSize = 14
g.TextFont=“HelveticaNeue-Light”
g.ForeColor = &cFFFFFF00
g.DrawString(“C”, 45, Me.Height / 1.5)
End Select[/code]
When i click the button stay as pressed,but when i click the other button still stay as pressed until i hover the mouse to the button.
How i change the state when i click the other button?

Can you upload a sample project? It is a lot easier to test than coding a similar example that might be different to your code/layout?

In the “other button’s” click event add this line:

CanvasXYZ.Invalidate()

Here is a example file sample

Do you want only one button to be selected at a time?

Yes Julian.

Not sure if I understand correctly but do you want to make some sort of tab bar controlling a pagepanel?

Something like this yes,the sample i post above is very simple.
1: User press the button and stay pressed.
2: User press the other buttons (pressed button back to normal)

Do you mean something like this?
Or better yet, make it a control set.

Here’s a simple example that is by no means complete, I’ve used a few more advanced techniques but it should give you a grounding in creating custom controls, you can then re-use that control across your app without having to recode every time you add a new button :slight_smile:

DropBox

Let me know if you get stuck

Its using a new Base_Canvas that you can use as a Super (see https://www.xojo.com/resources/creatingcustomcontrols.php)
Its using Design time properties (see https://forum.xojo.com/11705-custom-class-properties)

Thank you @ and @Marco Hof i will give a shot with your examples and i am back…