-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
LabelForm.cs
84 lines (57 loc) · 2.08 KB
/
LabelForm.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Threading.Tasks;
using TelegramBotBase.Args;
using TelegramBotBase.Controls.Hybrid;
using TelegramBotBase.Controls.Inline;
using TelegramBotBase.Enums;
using TelegramBotBase.Form;
namespace TelegramBotBase.Example.Tests.Controls;
public class LabelForm : AutoCleanForm
{
TelegramBotBase.Controls.Inline.Label _label;
ButtonGrid _buttonGrid;
String[] string_options = new string[] { "My test label", "Here is a different text", "*And this looks completely different.*", "Aha! another one.", "_Gotcha!_" };
public LabelForm()
{
DeleteMode = EDeleteMode.OnLeavingForm;
Init += LabelForm_Init;
}
private Task LabelForm_Init(object sender, InitEventArgs e)
{
//The "label" control
_label = new Label("My test label");
AddControl(_label);
//Optional...just for experimentation...
var bf = new ButtonForm();
bf.AddButtonRow("Toggle text", "toggle");
bf.AddButtonRow("Open menu", "menu");
_buttonGrid = new ButtonGrid(bf);
_buttonGrid.KeyboardType = EKeyboardType.ReplyKeyboard;
_buttonGrid.Title = "Choose your options:";
_buttonGrid.ButtonClicked += _buttonGrid_ButtonClicked;
AddControl(_buttonGrid);
return Task.CompletedTask;
}
private async Task _buttonGrid_ButtonClicked(object sender, ButtonClickedEventArgs e)
{
switch (e.Button.Value ?? "")
{
case "menu":
var mn = new Menu();
await NavigateTo(mn);
break;
case "toggle":
//Pick random string from array
var r = new Random((int)DateTime.UtcNow.Ticks);
String random_string;
do
{
random_string = string_options[r.Next(0, string_options.Length)];
if (random_string == null)
continue;
} while (random_string == _label.Text);
_label.Text = random_string;
break;
}
}
}