-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
MultiToggleButtonForm.cs
55 lines (46 loc) · 1.53 KB
/
MultiToggleButtonForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TelegramBotBase.Args;
using TelegramBotBase.Controls.Inline;
using TelegramBotBase.Enums;
using TelegramBotBase.Form;
namespace TelegramBotBase.Example.Tests.Controls;
public class MultiToggleButtonForm : AutoCleanForm
{
public MultiToggleButtonForm()
{
DeleteMode = EDeleteMode.OnLeavingForm;
Init += ToggleButtons_Init;
}
private Task ToggleButtons_Init(object sender, InitEventArgs e)
{
var mtb = new MultiToggleButton
{
Options = new List<ButtonBase> { new("Option 1", "1"), new("Option 2", "2"), new("Option 3", "3") }
};
mtb.SelectedOption = mtb.Options.FirstOrDefault();
mtb.Toggled += Tb_Toggled;
AddControl(mtb);
mtb = new MultiToggleButton
{
Options = new List<ButtonBase> { new("Option 4", "4"), new("Option 5", "5"), new("Option 6", "6") }
};
mtb.SelectedOption = mtb.Options.FirstOrDefault();
mtb.AllowEmptySelection = false;
mtb.Toggled += Tb_Toggled;
AddControl(mtb);
return Task.CompletedTask;
}
private void Tb_Toggled(object sender, EventArgs e)
{
var tb = sender as MultiToggleButton;
if (tb.SelectedOption != null)
{
Console.WriteLine(tb.Id + " was pressed, and toggled to " + tb.SelectedOption.Value);
return;
}
Console.WriteLine("Selection for " + tb.Id + " has been removed.");
}
}