我想在电报机器人中制作两行或更多行的嵌入式键盘,我知道如何将它们制成一行(在以下代码中):
bone
但是如何使第二行中的第三个按钮(或第二行中的最后两个按钮)呢?
答案 0 :(得分:1)
您可以在IEnumerable<IEnumerable<InlineKeyboardButton>>
构造函数中传递InlineKeyboardMarkup
,每个IEnumerable<InlineKeyboardButton>
都是单行,是这样:
// Buttons
InlineKeyboardButton urlButton1 = new InlineKeyboardButton();
InlineKeyboardButton urlButton2 = new InlineKeyboardButton();
InlineKeyboardButton urlButton3 = new InlineKeyboardButton();
urlButton1.Text = "Go URL1";
urlButton1.Url = "https://www.google.com/";
urlButton2.Text = "Go URL2";
urlButton2.Url = "https://www.bing.com/";
urlButton3.Text = "Go URL3";
urlButton3.Url = "https://www.yahoo.com/";
// Rows, can put multiple buttons!
InlineKeyboardButton[] row1 = new InlineKeyboardButton[] { urlButton1 };
InlineKeyboardButton[] row2 = new InlineKeyboardButton[] { urlButton2, urlButton3 };
// Set rows in Array of array | IEnamerable<IEnumerable<InlineKeyboardButton>>
InlineKeyboardButton[][] buttons = new InlineKeyboardButton[][] { row1, row2 };
// Keyboard
InlineKeyboardMarkup inline = new InlineKeyboardMarkup(buttons);
// Send message!
bot.SendTextMessageAsync(chatId, sb.ToString(), ParseMode.Html, true, false, 0, inline);