我已经Console.WriteLine拨打了一些电话进行测试,但它们没有出现在输出框中?
public static ArrayList myDeliveries = new ArrayList();
public mainForm(){
InitializeComponent();
}
private void mainForm_Load(object sender, EventArgs e){
if (!File.Exists("../../MealDeliveries.txt")){
MessageBox.Show("File not found!");
return;
}
using (StreamReader sr = new StreamReader("../../MealDeliveries.txt")){
//first line is delivery name
string strDeliveryName = sr.ReadLine();
Console.WriteLine("Test content");
while (strDeliveryName != null){
//other lines
Delivery d = new Delivery(
strDeliveryName,
sr.ReadLine(),
sr.ReadLine(),
sr.ReadLine(),
sr.ReadLine(),
sr.ReadLine(),
sr.ReadLine()
);
mainForm.myDeliveries.Add(d);
//check for further values
strDeliveryName = sr.ReadLine();
}
}
displayDeliveries();
}
private void displayDeliveries(){
lstDeliveryDetails.Items.Clear();
Console.WriteLine("Test content");
Console.WriteLine(mainForm.myDeliveries.Count);
foreach (Delivery d in mainForm.myDeliveries){
lstDeliveryDetails.Items.Add(d.DeliveryName);
}
}
Run Code Online (Sandbox Code Playgroud)
谁能帮忙?
Zac*_*son 96
Console输出到控制台窗口,Winforms应用程序不显示控制台窗口.您应该可以使用System.Diagnostics.Debug.WriteLine将输出发送到IDE中的输出窗口.
编辑:关于问题,你确认你mainForm_Load的实际被调用了吗?你可以在开头mainForm_Load看一个断点.如果它没有被调用,我怀疑它mainForm_Load没有与Load事件联系起来.
此外,它更有效,通常更好地覆盖On{EventName}而不是{EventName}从派生类内部订阅(在您的情况下覆盖OnLoad而不是Load).
小智 17
使用Console.WriteLine( "Test" );能够将日志消息写入 Windows 窗体/WPF 项目的 Visual Studio 中的输出窗口(查看菜单 --> 输出)。
然而,我遇到了一个情况,它不起作用,只能System.Diagnostics.Debug.WriteLine( "Test" );起作用。我重新启动 Visual Studio 并Console.WriteLine()再次开始工作。似乎是 Visual Studio 的错误。
dav*_*rvw 12
如果要Console.WriteLine("example text")在"调试输出"窗口中显示输出,请暂时将应用程序的输出类型从控制台应用程序更改为Windows应用程序.
从菜单中选择Project + Properties,然后导航到Output type:下拉,切换到Windows Application然后运行您的应用程序
当然,您应该将其更改为构建旨在在IDE外部运行的控制台应用程序.
(使用Visual Studio 2008和2010进行测试,预计它也应该适用于后期版本)
尝试取消选中复选框 \xe2\x80\x9c 将所有输出窗口文本重定向到立即窗口\xe2\x80\x9d
\nTools => Options => Debugging => General\nRun Code Online (Sandbox Code Playgroud)\n我检查了它,所有内容都写在立即窗口中,而不是输出窗口中
\n| 归档时间: |
|
| 查看次数: |
136655 次 |
| 最近记录: |