Re: Console.Clear()
- From: rowe_newsgroups <rowe_email@xxxxxxxxx>
- Date: Tue, 18 Sep 2007 06:19:40 -0700
On Sep 18, 8:03 am, "Just Me" <news.microsoft.com> wrote:
sure. its a vb.net windows applicaiton with one form.
'//In a button handler
console.clear()
console.writeline("Hello World")
'// Thats it.
Cheers
"rowe_newsgroups" <rowe_em...@xxxxxxxxx> wrote in message
news:1190111056.417550.41460@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Sep 18, 4:13 am, "Just Me" <news.microsoft.com> wrote:
Yes, but you are using a console application. I am viewing the output
window
in windows forms application.
"rowe_newsgroups" <rowe_em...@xxxxxxxxx> wrote in message
news:1190040486.080263.33600@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Sep 17, 4:56 am, "Just Me" <news.microsoft.com> wrote:
I am writing a small windows applicationa and I am writing
console.writeline
data to the console window. But i wanted to clear the area before
writing
to
the window.
I found the console.clear method, but when I run it it fails with an
uinhandled exception and the exception is that it does not have the
handle
to the window.
IM assuming, I need to determine the console windo handle, but Im not
sure,
has anyone used this, can point me in the right direction.
Thanks a million
I'm not sure I follow you - I can use Console.Clear with no problems:
////////////////////////
Module Module1
Sub Main()
For i As Integer = 0 To 5
Console.WriteLine("hello world {0}", i.ToString())
Next i
System.Threading.Thread.Sleep(1000)
Console.Clear()
Console.WriteLine("Console Cleared")
Console.Read()
End Sub
End Module
////////////////////////
The above runs with no problems for me - is it throwing an exception
for you? If not please post a small but complete code sample that can
reproduce the error for me.
Thanks,
Seth Rowe
Alright, would you mind posting some code that I can use to replicate
the problem?
Thanks,
Seth Rowe
Okay, now I'm getting worried. Did you run the application without the
Console.Clear() call? Unless I've really forgotten something Window's
based applications ignore the calls to the Console class, as it
doesn't exist.
Excerpt from the MSDN documentation (http://msdn2.microsoft.com/en-us/
library/system.console(VS.71).aspx):
<quote>
The Console class provides basic support for applications that read
characters from, and write characters to, the console. If the console
does not exist, as in a Windows-based application, writes to the
console are not displayed and no exception is raised.
</quote>
If you really need to have both a console window and standard forms
you need to create a console project. Then reference the appropriate
dll's (such as System.Windows.Forms) and then create the form classes
you need.
The following code sample requires a new console project and
references to System.Windows.Forms and System.Drawing to work.
////////////////
Imports System.Windows.Forms
Imports System.Drawing
Module Module1
Sub Main()
Application.EnableVisualStyles()
Console.WriteLine("Showing form...")
Console.WriteLine("Be sure to look behind me, the form is
sometimes hidden behind me")
System.Threading.Thread.Sleep(1000)
Dim f As New Form()
f.Text = "My Custom Form"
Dim b As New Button()
AddHandler b.Click, AddressOf button_Click
b.Width = 100
b.Location = New Point(100, 100)
b.Text = "Click Me"
f.Controls.Add(b)
f.ShowDialog()
Console.WriteLine("You just closed the form")
Console.WriteLine("Goodbye")
System.Threading.Thread.Sleep(1000)
End Sub
Private Sub button_Click(ByVal sender As Object, ByVal e As
EventArgs)
Console.Clear()
Console.WriteLine("Hello World from the Windows Form!")
Console.WriteLine("The current time is: {0}",
DateTime.Now.ToString("h:m:s tt"))
End Sub
End Module
////////////////
Hope That helps!
Thanks,
Seth Rowe
.
- Follow-Ups:
- Re: Console.Clear()
- From: Just Me
- Re: Console.Clear()
- References:
- Console.Clear()
- From: Just Me
- Re: Console.Clear()
- From: rowe_newsgroups
- Re: Console.Clear()
- From: Just Me
- Re: Console.Clear()
- From: rowe_newsgroups
- Re: Console.Clear()
- From: Just Me
- Console.Clear()
- Prev by Date: Editing Listview Items and Subitems
- Next by Date: Re: Editing Listview Items and Subitems
- Previous by thread: Re: Console.Clear()
- Next by thread: Re: Console.Clear()
- Index(es):
Loading