0

my console application in like below :

static void Main(string[] args)
{
    string Now = DateTime.Now.ToShortDateString();
    if (Now == "2011/08/12")
    {
        Console.Clear();
        Console.Write("Money..........");
        Console.Read();
    }
    else
    {
        int n = 6;

        var result = string.Join("\r\n", from i in Enumerable.Range(1, n)
                                         where i != 2
                                         let stars = Enumerable.Repeat('*', i)
                                         let indent = new string(' ', n - i)
                                         select indent + string.Join(" ", stars));

        Console.WriteLine(result);
        Console.Read();
    }
} 

the upper codes are in c#

my questions :
1- how can we find some shape examples in console application like the upper example with *!
the upper example with stars is too simple / i am looking for some better shapes like hanging somebody (just for fun)
2- how can i move console.write window with code ?
3- how can i move shape inside console.write window ?
4- how can i set consol.write window positioning ?

thanks in advance

SilverLight
  • 19,668
  • 65
  • 192
  • 300
  • @Shamim Hafiz sorry / i edit my Q – SilverLight Aug 11 '11 at 09:05
  • I am sorry, i dont understand what your code does nor what you wish to do. Either give the full code, so can compile and do some fix. – Zenwalker Aug 11 '11 at 09:17
  • @zenwalker : hi / the upper codes in Q are ok and u can test them in a console application / besides my Q's have nothing to do with these codes! plz let me to know that is there any wrong with my Q's! – SilverLight Aug 11 '11 at 09:23
  • I did run your code which you have pased in Q, its not compiling. – Zenwalker Aug 11 '11 at 09:28

2 Answers2

1

Have you looked at MSDN http://msdn.microsoft.com/en-us/library/system.console.aspx

1 - You will have to work out the shapes yourself, enjoy.

Here is a code that does somthing but you already have some in your example.

int pos = 0
int limit = 80
while (true)
{
    StringBuilder line  = new StringBuilder(limit);
    for(int i = 0; i < limit; i++)
    {
        if (i = pos)
        {
            line.Append("A");
        }
        else
        {
            line.Append(" ");
        }
    }
    Console.WriteLine(line.ToString());
    if (pos = (limit - 1))
    {
        pos = 0;
    }
    else
    {
        pos++;
    }
}

2 - You can move the console window with Console.WindowLeft and Console.WindowsTop

3 - Shape is the wrong word and idea here, you can only read and write lines of text. You could create the impression of a moving shape by using a char say 0 or as background, populating the whole line as "blank", Then use some other chars to represent your shape. See the example above.

4 - Same as 2.

Jodrell
  • 34,946
  • 5
  • 87
  • 124
1

To relocate the actual console window, you'd need to do SetWindowPos with GetConsoleWindow (Win32 API) as described here.

[DllImport("kernel32.dll", ExactSpelling = true)]
private static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);

//    
SetWindowPos(GetConsoleWindow(), 0, x, y, 0, 0, SWP_NOSIZE);

On manipulating shapes inside the console window, have a look at MonoCurses. I'm not sure whether it works on Windows yet, but is quite advanced (having Window, Dialog, Application abstractions and a lot of widgets for data entry)

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633