我想在列表框中显示所有打印机 [英] i want to show all the printers in a listbox

查看:54
本文介绍了我想在列表框中显示所有打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先是我的代码

hi for starters heres my code

private void PrinterList()
        {
            throw new NotImplementedException();

            foreach (string sPrinters in PrinterSettings.InstalledPrinters)
            {
                listBox1.Items.Add(sPrinters);
            }
        }



我的问题

i得到错误/警告/我的foreach - 代码无法访问


my problem"
i get a error/warning/ on my foreach - code is unreachable

推荐答案

你在方法中做的第一件事是你抛出一个异常。之后没有代码会在这个方法中执行,因此就是警告。 />


删除或注释掉例外:

The first thing you do in the method is that you throw an exception. No code after that is going to be executed inside this method, thus the warning.

So remove or comment out the exception:
private void PrinterList()
        {
            //throw new NotImplementedException();

            foreach (string sPrinters in PrinterSettings.InstalledPrinters)
            {
                listBox1.Items.Add(sPrinters);
            }
        }


这篇关于我想在列表框中显示所有打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆