1、获取本机所有IP显示到combobox,并初始化combobox为第一个IP,还需要过滤掉回环IP
IPAddress[] hostIpList = Dns.GetHostAddresses(Dns.GetHostName()); //comboBox1.Text = string.Empty; comboBox1.ResetText(); comboBox1.SelectedIndex = -1; foreach (IPAddress ip in hostIpList) { Console.WriteLine("Ip[]: {1}", ip.ToString()); if (IPAddress.IsLoopback(ip) != true) comboBox1.Items.Add(ip.ToString()); } comboBox1.SelectedIndex = 0;
2、判断combobox是否有内容,以及某个Item是否为空
if (this.comboBox1.Items.Count > 0) { String s = this.comboBox1.Items[0].ToString(); if (String.IsNullOrEmpty(s) == false) comboBox1.SelectedIndex = 0; else MessageBox.Show("Host's ipaddress is empty!"); } else { MessageBox.Show("Can not get any host's ipaddress!\n" + "Please press CANCEL to cancel!", "ERROR");//, MessageBoxButtons.OKCancel); }
3、messageBox控件使用介绍
来源: http://www.cnblogs.com/Tammie/archive/2011/08/05/2128623.html
// 标题为空, 按钮只显示OK MessageBox.Show("Hello~~~~"); // 标题为"ERROR", 按钮只显示OK MessageBox.Show("There are something wrong!","ERROR"); // 自定义消息盒 消息标题"Confirm Message", 按钮有两个: OK 和 Cancel if (MessageBox.Show("Delete this user?", "Confirm Message",MessageBoxButtons.OKCancel) == DialogResult.OK) // 带有ICON的message if (MessageBox.Show("Delete this user?", "Confirm Message",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK) // 默认为cancel按钮的方法 if (MessageBox.Show("Delete this user?", "Confirm Message", MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2) == DialogResult.OK) // 反向显示, 类似于ubuntu里的那种按钮效果 if (MessageBox.Show("Delete this user?", "Confirm Message", MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2,MessageBoxOptions.RtlReading) ==DialogResult.OK) // 添加help按钮 if (MessageBox.Show("Delete this user?", "Confirm Message", MessageBoxButtons.OKCancel,MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.RightAlign,true) ==DialogResult.OK) // 指定帮助文件的路径 if (MessageBox.Show("Delete this user?", "Confirm Message", MessageBoxButtons.OKCancel,MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading,@"/folder/file.htm") == DialogResult.OK) //HelpNavigator指定常数来指示要显示的帮助文件元素, Find帮助文件将打开到搜索页 if (MessageBox.Show("Delete this user?", "Confirm Message", MessageBoxButtons.OKCancel,MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading,@"/folder/file.htm", HelpNavigator.Find) == DialogResult.OK)
over