Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

c# - Console.WriteLine does not show up in Output window

I have put some Console.WriteLine calls in to test, but they aren't appearing in the output box?

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);

    }
}

Can anyone help??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Console outputs to the console window and Winforms applications do not show the console window. You should be able to use System.Diagnostics.Debug.WriteLine to send output to the output window in your IDE.

Edit: In regards to the problem, have you verified your mainForm_Load is actually being called? You could place a breakpoint at the beginning of mainForm_Load to see. If it is not being called, I suspect that mainForm_Load is not hooked up to the Load event.

Also, it is more efficient and generally better to override On{EventName} instead of subscribing to {EventName} from within derived classes (in your case overriding OnLoad instead of Load).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...