private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { string printer = this.comboBox2.SelectedItem.ToString(); if (this.comboBox2.SelectedItem != null) //判断是否有选中值 { if (PrinterOperate.SetDefaultPrinter(printer)) //设置默认打印机 { this.label3.Text = "默认打印机:" + printer; MessageBox.Show(printer + "设置为默认打印机成功!"); } else { MessageBox.Show(printer + "设置为默认打印机失败!"); } } }
private void Form1_Load(object sender, EventArgs e) { PrinterOperate.GetPrinters(this.label3, this.comboBox2); if (NetworkOperate.Ping("192.168.1.3")) { this.label6.Text = "● 网络连接正常"; this.label6.ForeColor = System.Drawing.Color.ForestGreen; this.label5.Text = "本机IP:" + NetworkOperate.GetLocalIP(); string strServer = @"\\192.168.1.3"; string strUserName = "******"; string strUserPD = "ybsnyyzq"; System.Diagnostics.Process.Start("net.exe", "use \\\\" + strServer + " /user:\"" + strUserName + "\" \"" + strUserPD + "\""); } else { this.label6.Text = "● 网络连接异常"; this.label6.ForeColor = System.Drawing.Color.Crimson; MessageBox.Show("内网已断开连接, 请检查网线以及交换机"); } }