我正在使用API调用从Web服务器返回一些XML数据.XML数据采用以下格式:
<forismatic>
<quote>
<quoteText>The time you think you're missing, misses you too.</quoteText>
<quoteAuthor>Ymber Delecto</quoteAuthor>
<senderName></senderName>
<senderLink></senderLink>
<quoteLink>http://forismatic.com/en/55ed9a13c0/</quoteLink>
</quote>
</forismatic>
Run Code Online (Sandbox Code Playgroud)
我可以成功检索原始XML数据,我想将<quoteText>和<quoteAuthor>节点值添加到字符串但似乎无法执行此操作.我目前的代码:
private void btnGetQuote_Click(object sender, EventArgs e)
{
WebRequest req = WebRequest.Create("http://api.forismatic.com/api/1.0/");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
string reqString = "method=getQuote&key=457653&format=xml&lang=en";
byte[] reqData = Encoding.UTF8.GetBytes(reqString);
req.ContentLength = reqData.Length;
using (Stream reqStream = req.GetRequestStream())
reqStream.Write(reqData, 0, reqData.Length);
using (WebResponse res = req.GetResponse())
using (Stream resSteam = res.GetResponseStream())
using (StreamReader sr = new StreamReader(resSteam))
{
string xmlData = …Run Code Online (Sandbox Code Playgroud) 我有一个Windows窗体,我为连接到计算机的每个监视器添加一个按钮控件.当然,作为从PC到PC的显示器数量,我想每个显示器自动添加一个按钮并添加它们,以便它们连续显示.
目前我的代码如下:
foreach (var screen in Screen.AllScreens)
{
Button monitor = new Button
{
Name = "Monitor" + screen,
AutoSize = true,
Size = new Size(100, 60),
Location = new Point(12, 70),
ImageAlign = ContentAlignment.MiddleCenter,
Image = Properties.Resources.display_enabled,
TextAlign = ContentAlignment.MiddleCenter,
Font = new Font("Segoe UI", 10, FontStyle.Bold),
ForeColor = Color.White,
BackColor = Color.Transparent,
Text = screen.Bounds.Width + "x" + screen.Bounds.Height
};
monitorPanel.Controls.Add(monitor);
}
Run Code Online (Sandbox Code Playgroud)
这是有效的,它只是将每个按钮放在彼此的顶部,有多个显示器(正如我预期的那样):
我想要实现的是每个按钮都被添加,但是彼此相邻.我尝试了各种各样的线程,在谷歌等搜索无济于事.有人能指出我正确的方向吗?
我正在ComboBox使用从"配置"形式的四个文本框中获取的值列表填充.代码有效,但我遇到的问题是这些文本框中的某些文本框是空白的.如果任何文本框为空,那么我的ComboBox列表中有空格.我的代码:
comboFms.Items.Clear();
string[] fmsDB = new string[] { "Select FMS Database", fms1, fms2, fms3, fms4 };
comboFms.Items.AddRange(fmsDB);
this.cboFms.Text = "Select FMS Database";
this.cboFms.Enabled = true;
Run Code Online (Sandbox Code Playgroud)
在此示例中,仅fms1具有值.这导致下拉列表显示如下:
有什么办法可以从字符串数组或ComboBox中排除空白值吗?