using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Printing;
using System.IO.Ports;
namespace Printer
{
public partial class portname : Window
{
PrintServer server = new PrintServer();
public portname()
{
this.InitializeComponent();
foreach (PrintQueue queue in server.GetPrintQueues())
{
com_pinter.Items.Add(queue.FullName);
}
var DefaultPrinter = new LocalPrintServer().DefaultPrintQueue;
string default_name=DefaultPrinter.FullName;
txt_dpn.Text = "Default printe is " + " " + default_name.ToUpper();
string default_port = DefaultPrinter.QueuePort.Name;
txt_pn.Text = "PortName is" + " " + default_port.ToUpper();
}
private void com_pinter_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
foreach (PrintQueue queue in server.GetPrintQueues())
{
string selecteditem = com_pinter.SelectedItem.ToString();
string portname = queue.FullName;
SerialPort mySerialPort = new SerialPort(queue.QueuePort.Name);
btn_br.Content = mySerialPort.BaudRate;
btn_db.Content = mySerialPort.DataBits;
btn_pty.Content = mySerialPort.Parity;
btn_sb.Content = mySerialPort.StopBits;
if (selecteditem == portname)
{
string select_portname = queue.QueuePort.Name;
txt_pn.Text = "PortName is" + " " + select_portname.ToUpper();
}
}
}
}
}
但我不知道这种方式是否正确以获得这样的输出(上图)。我只是搞砸了。如果你知道正确的方式,请告诉我我只是升级它。
最后我需要找到流控制(软件或硬件)。根据上图,组合框必须是软件设备的设备。所以我必须动态找到该值(s/w 或 h/w)。