Changing icons programmatically into a segmented control

I have been searching, but I haven’t found anything.

I would have suspected it was something like me.items(0).icon = darkbutton, but that doesn’t work.

I am trying to make something that is like the left, center, right justification buttons of a word processor application.

What you want does not exist in that control.

You could create you own control by placing BevelButtons next to each other. They have the Icon you want. You will have to do some coding for that to behave like a segmentedControl with the sticky buttons, but all is possible with pictures and an array of booleans.

The other way is to create your own control with a canvas.

[quote=382811:@Michel Bujardet]What you want does not exist in that control.

You could create you own control by placing BevelButtons next to each other. They have the Icon you want. You will have to do some coding for that to behave like a segmentedControl with the sticky buttons, but all is possible with pictures and an array of booleans.

The other way is to create your own control with a canvas.[/quote]

Can you not just make shit up? Thanks.

What do you mean it’s not working? Elaborate.

After “me.Items(0).” xojo doesn’t want to auto-complete it with icon. I am in the action event. What code and what event should I be working in?

You can do it anywhere. It doesn’t complete for me, either, but it does work. Tim tested on macOS and I tested on Windows.

That’s your problem. Don’t use Auto-Complete to guess at features, read the documentation.
http://documentation.xojo.com/index.php/SegmentedControl

[quote=382828:@Tim Parnell]That’s your problem. Don’t use Auto-Complete to guess at features, read the documentation.
http://documentation.xojo.com/index.php/SegmentedControl[/quote]
I second that. Autocomplete is useful but not authoritative.

Yes, it worked for me. Thank you all.

While I am at it, how do I set the focus of a segmented control programmatically? Say there are three buttons and I want the second button selected—such as popupmenu.listindex = 5.

Example code for that is in the documentation.

I have tried many things and can’t find it ¯\(?)

I have tried setting:

SegmentedControl1.index = 1
SegmentedControl1.TabIndex = 1
SegmentedControl1.TabPanelIndex = 1
SegmentedControl1.PanelIndex = 1

It’s literally the first example on the link Tim provided.

The problem for you is that first you have to declare a SegmentedControlItem, then set it to the item of your SegmentedControl.

If you use MBS Plugin, you could get the NSSegmentedControlMBS object for your control and use the NSSegmentedControlMBS.imageForSegment method to set the icon for each segment.

Dim s As SegmentedControlItem = SegmentedControl.Items(1) // Index starts at 0, so 1 is 2nd Item s.Selected = True

[quote=383313:@Sascha S]Dim s As SegmentedControlItem = SegmentedControl.Items(1) // Index starts at 0, so 1 is 2nd Item s.Selected = True[/quote]

Thank you for the reply. While that does change which button is selected, it causes the icons I use in each segment to act oddly, almost like a ghostly image. Also, while it somewhat selects the button, it does not trigger the code inside like if I was programmatically changing a listbox.