我列举了连接在PC上的打印机.我是用C#System.Printing命名空间完成的.它运作良好.但主要是它显示软件打印机,如Microsoft XPS Document writer,Microsoft Fax等.我想知道是否可以从枚举中删除这些ssoftware打印机.我所做的代码如下所示:
PrintQueue printQueue = null;
LocalPrintServer localPrintServer = new LocalPrintServer();
// Retrieving collection of local printer on user machine
PrintQueueCollection localPrinterCollection =
localPrintServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local,
EnumeratedPrintQueueTypes.Connections });
System.Collections.IEnumerator localPrinterEnumerator =
localPrinterCollection.GetEnumerator();
while (localPrinterEnumerator.MoveNext())
{
// Get PrintQueue from first available printer
printQueue = (PrintQueue)localPrinterEnumerator.Current;
if (!printQueue.IsOffline)
{
MessageBox.Show(printQueue.FullName.ToString());
string s = "Printer found " + printQueue.FullName.ToString();
listBox1.Items.Add(s);
}
else
{
// No printer exist, return null PrintTicket
// return null;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试检测usb到达事件.我试图覆盖wndproc()以获取我的消息.但我正面临着Windows消息的错误.
错误是:
The name 'WM_DEVICECHANGE' does not exist in the current context
The name 'DBT_DEVICEARRIVAL' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)
这也是我尝试过的代码.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32.SafeHandles;
namespace USBCheckerApp
{
public partial class Form1 : Form
{
bool bDeviceFound = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
if (!bDeviceFound)
{
button1.Enabled = false;
}
}
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
protected override void WndProc(ref Message …Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序来绘制图表并在图表中显示图例.
这是我到目前为止所做的.没有图例部分图形正确绘制.我试图绘制像这个MSDN链接的传奇.在运行时我收到此错误.
尝试使用谷歌搜索.但我不知道具体原因是什么.
Chart gammaPlotChart = new Chart();
ChartArea chart4Area = new ChartArea();
chart4Area.Name = "Default";
Series gammaValues = new Series();
gammaValues.Name = "LogGamma";
gammaValues.ChartType = SeriesChartType.Line;
gammaValues.XValueType = ChartValueType.Double;
gammaValues.YValueType = ChartValueType.Double;
gammaPlotChart.ChartAreas[0].AxisX.Minimum = 1.4;
gammaPlotChart.ChartAreas[0].AxisX.Interval = 0.2;
gammaPlotChart.ChartAreas[0].AxisX.Maximum = 5.0;
gammaPlotChart.ChartAreas[0].AxisY.Minimum = 0;
gammaPlotChart.ChartAreas[0].AxisY.Interval = 0.5;
gammaPlotChart.ChartAreas[0].AxisY.Maximum = 3.0;
gammaPlotChart.Series.Add(gammaValues);
gammaPlotChart.Series["LogGamma"].Points.DataBindXY(sRGBValues.greyScaleValues.LogV, sRGBValues.greyScaleValues.LogL);
gammaPlotChart.Legends.Add(new Legend("Legend1"));
gammaPlotChart.Legends["Legend1"].DockedToChartArea = "Default";
gammaPlotChart.Series["LogGamma"].Legend = "Legend1";
gammaPlotChart.Series["LogGamma"].IsVisibleInLegend = true;
gammaPlotChart.Legends["Legend1"].CellColumns.Add(new LegendCellColumn("Name", LegendCellColumnType.Text, "LEGENDTEXT"));
gammaPlotChart.Legends["Legend1"].CellColumns.Add(new LegendCellColumn("Sym", LegendCellColumnType.SeriesSymbol, "Mist"));
Font font = new Font("Arial", …Run Code Online (Sandbox Code Playgroud) 如何在全局范围内为win形式的所有文本框设置背景颜色?我们可以将它设置在全局变量中并在需要时使用吗?我需要从全局变量而不是编写 form_load 中设置控件的背景颜色
mytextbox1.BackColor = Color.Red;
mytextbox2.BackColor = Color.Red;
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,每次处理时都需要重新初始化.就像是 :
private void method(int someValue, int someValue2)
{
obj.val1 = someNewValue;
obj1.Val2 = someNewValue2;
}
Run Code Online (Sandbox Code Playgroud)
将重复调用此方法.所以我怀疑每次重新初始化对象有什么用呢?就像是;
private void method(int someValue, int someValue2)
{
obj = new object();
obj.Val1 = someNewValue;
obj1.Val2 = someNewValue2;
}
Run Code Online (Sandbox Code Playgroud)
我知道分配null给一个对象并没有什么结果.或者我应该实施IDisposable?问题是我每次都需要新的价值.在这种情况下,分配是否正常?如果我重新初始化,我不知道已经分配的对象会发生什么,如第二种方法所示.