Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按所需行号制作电报机器人内联键盘_C#_Winforms_Telegram Bot - Fatal编程技术网

C# 按所需行号制作电报机器人内联键盘

C# 按所需行号制作电报机器人内联键盘,c#,winforms,telegram-bot,C#,Winforms,Telegram Bot,我想在电报机器人中制作两行或更多行的内联键盘,我知道如何制作一行(在以下代码中): 但是如何制作第二行中的第三个按钮(或第二行中的最后两个按钮)?您可以在InlineKeyboardMarkup构造函数中传递IEnumerable,并且每个IEnumerable都是单行,如下所示: //按钮 InlineKeyboardButton urlButton1=新的InlineKeyboardButton(); InlineKeyboardButton urlButton2=新的InlineKeybo

我想在电报机器人中制作两行或更多行的内联键盘,我知道如何制作一行(在以下代码中):


但是如何制作第二行中的第三个按钮(或第二行中的最后两个按钮)?

您可以在
InlineKeyboardMarkup
构造函数中传递
IEnumerable
,并且每个
IEnumerable
都是单行,如下所示:

//按钮
InlineKeyboardButton urlButton1=新的InlineKeyboardButton();
InlineKeyboardButton urlButton2=新的InlineKeyboardButton();
InlineKeyboardButton urlButton3=新的InlineKeyboardButton();
urlButton1.Text=“转到URL1”;
Url按钮1.Url=”https://www.google.com/";
urlButton2.Text=“转到URL2”;
Url按钮2.Url=”https://www.bing.com/";
urlButton3.Text=“转到URL3”;
Url按钮3.Url=”https://www.yahoo.com/";
//行,可以放多个按钮!
InlineKeyboardButton[]行1=新的InlineKeyboardButton[]{urlButton1};
InlineKeyboardButton[]行2=新的InlineKeyboardButton[]{urlButton2,urlButton3};
//在数组| IEnamerable的数组中设置行
InlineKeyboardButton[][]按钮=新的InlineKeyboardButton[]{row1,row2};
//键盘
InlineKeyboardMarkup inline=新的InlineKeyboardMarkup(按钮);
//发送消息!
SendTextMessageAsync(chatId,sb.ToString(),ParseMode.Html,true,false,0,内联);
    StringBuilder sb = new StringBuilder(txtBody.Text);

    int chatId="123456789"; //not real Chat ID


    // 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/";

    InlineKeyboardButton[] buttons = new InlineKeyboardButton[] { urlButton1, urlButton2 , urlButton3};
    InlineKeyboardMarkup inline = new InlineKeyboardMarkup(buttons);

    // Send message!
    bot.SendTextMessageAsync(chatId, sb.ToString(), ParseMode.Html, true, false, 0, inline);