Click here to Skip to main content
15,860,972 members
Home / Discussions / C#
   

C#

 
QuestionWhenever code shows "Console.WriteLine..." replace with textbox Pin
Agewiz22-Jun-16 6:46
Agewiz22-Jun-16 6:46 
QuestionRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Eddy Vluggen22-Jun-16 7:00
professionalEddy Vluggen22-Jun-16 7:00 
AnswerRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Agewiz22-Jun-16 11:50
Agewiz22-Jun-16 11:50 
AnswerRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Afzaal Ahmad Zeeshan22-Jun-16 7:12
professionalAfzaal Ahmad Zeeshan22-Jun-16 7:12 
PraiseRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Eddy Vluggen22-Jun-16 8:04
professionalEddy Vluggen22-Jun-16 8:04 
GeneralRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Agewiz22-Jun-16 12:02
Agewiz22-Jun-16 12:02 
AnswerRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Afzaal Ahmad Zeeshan22-Jun-16 12:04
professionalAfzaal Ahmad Zeeshan22-Jun-16 12:04 
AnswerRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
BillWoodruff22-Jun-16 19:23
professionalBillWoodruff22-Jun-16 19:23 
I am not familiar with WinPhone C# programming, however, there is a general strategy I've often used to deal with a similar issue:

1. set a global flag that will determine where output goes: to Console, or TextBox

private const bool OutputToConsole = true; // true for debugging

2. in your code:
C#
private void SomeMethod(string blah)
{
    if(OutputToConsole)
    {
        Console.WriteLine("my blah is:" + blah);
    }
    else
    {
        someTextBox.Text = String.Format("my blah is: {0}", blah);
    }
}
This gets tiresome, but you can make this a bit easier to write by pre-defining template strings to use, and wrapping the whole thing up in an Extension Method for Type String:
C#
public static class StringExtensions
{
    // global setting for output target
    public static bool OutputToConsole = false;

    private static StringBuilder sb = new StringBuilder();

    public static void WriteString(this string content, bool toconsole, TextBox tbxtarget = null, string template = "")
    {
        sb.Clear();

        sb.Append((template == "")
            ? content
            : String.Format(template, content));

        if (OutputToConsole || toconsole || tbxtarget == null)
        {
            Console.WriteLine(sb.ToString());
        }
        else
        {
            tbxtarget.Text = sb.ToString();
        }
    }
}
So, now, if I have two TextBoxes on some Form, 'textBox1, and 'textBox2, and a Button, 'button1, I can:
C#
public const string template0 = "blah state is: {0}";

private void button1_Click(object sender, EventArgs e)
{
    "medium blah".WriteString(true, template: template0);
    "empty blah".WriteString(false, textBox2, template0);
}
The first call to 'WriteString writes "blah state is: medium blah" to the Console, the second writes "blah state is: empty blah" to 'textBox2.

Note: I assume Windows Phone programming supports Extension Methods; if that's not the case, let me know.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008

SuggestionRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Richard Deeming23-Jun-16 2:09
mveRichard Deeming23-Jun-16 2:09 
GeneralRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
BillWoodruff23-Jun-16 3:05
professionalBillWoodruff23-Jun-16 3:05 
GeneralRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Richard Deeming23-Jun-16 7:14
mveRichard Deeming23-Jun-16 7:14 
GeneralRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
BillWoodruff26-Jun-16 4:48
professionalBillWoodruff26-Jun-16 4:48 
QuestionDevExpress.XtraGrid.Views.Grid.GridView changing the data by Mouse Scrolling Pin
po_saa22-Jun-16 5:46
po_saa22-Jun-16 5:46 
AnswerREPOST Re: DevExpress.XtraGrid.Views.Grid.GridView changing the data by Mouse Scrolling Pin
Dave Kreskowiak22-Jun-16 6:01
mveDave Kreskowiak22-Jun-16 6:01 
QuestionMeaning of errors logged by FileSystemWatcher.Error Pin
srikrishnathanthri22-Jun-16 1:24
srikrishnathanthri22-Jun-16 1:24 
AnswerRe: Meaning of errors logged by FileSystemWatcher.Error Pin
Eddy Vluggen22-Jun-16 1:50
professionalEddy Vluggen22-Jun-16 1:50 
GeneralRe: Meaning of errors logged by FileSystemWatcher.Error Pin
srikrishnathanthri22-Jun-16 19:47
srikrishnathanthri22-Jun-16 19:47 
GeneralRe: Meaning of errors logged by FileSystemWatcher.Error Pin
Eddy Vluggen23-Jun-16 1:31
professionalEddy Vluggen23-Jun-16 1:31 
QuestionThe database type “GenericDatabase” does not support asynchronous operations Pin
srikrishnathanthri22-Jun-16 1:13
srikrishnathanthri22-Jun-16 1:13 
AnswerRe: The database type “GenericDatabase” does not support asynchronous operations Pin
Eddy Vluggen22-Jun-16 1:48
professionalEddy Vluggen22-Jun-16 1:48 
AnswerRe: The database type “GenericDatabase” does not support asynchronous operations Pin
Dave Kreskowiak22-Jun-16 3:44
mveDave Kreskowiak22-Jun-16 3:44 
Questionneed help to send multiple sms using excel file in c# windows application Pin
trilok pandey21-Jun-16 1:39
trilok pandey21-Jun-16 1:39 
AnswerRe: need help to send multiple sms using excel file in c# windows application Pin
Dave Kreskowiak21-Jun-16 3:10
mveDave Kreskowiak21-Jun-16 3:10 
GeneralRe: need help to send multiple sms using excel file in c# windows application Pin
EveryNameIsTakenEvenThisOne21-Jun-16 21:37
professionalEveryNameIsTakenEvenThisOne21-Jun-16 21:37 
GeneralRe: need help to send multiple sms using excel file in c# windows application Pin
OriginalGriff21-Jun-16 21:54
mveOriginalGriff21-Jun-16 21:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.