Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Clearing the Console

Clearing the Console

Scheduled Pinned Locked Moved C#
csharp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    extremeg
    wrote on last edited by
    #1

    How can clear the DOS Console from a C# console application. ...the mind is not a vessel to be filled but a fire to ignited

    H 1 Reply Last reply
    0
    • E extremeg

      How can clear the DOS Console from a C# console application. ...the mind is not a vessel to be filled but a fire to ignited

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      This will be possible in either .NET 2.0 or Longhorn (no sure exactly which since release details are still sketchy) with Console.Clear, but for now you have to rely on other ways. One article here on CP presents such a way: http://www.codeproject.com/csharp/winconsole.asp[^]. There's also a programmatic way, but you'll have to P/Invoke some native functions: http://support.microsoft.com/support/kb/articles/q99/2/61.asp[^].

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      H 1 Reply Last reply
      0
      • H Heath Stewart

        This will be possible in either .NET 2.0 or Longhorn (no sure exactly which since release details are still sketchy) with Console.Clear, but for now you have to rely on other ways. One article here on CP presents such a way: http://www.codeproject.com/csharp/winconsole.asp[^]. There's also a programmatic way, but you'll have to P/Invoke some native functions: http://support.microsoft.com/support/kb/articles/q99/2/61.asp[^].

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        H Offline
        H Offline
        Hauptman n
        wrote on last edited by
        #3

        but with this method, you give up your portability antoher method is, when you fill up the Console with \n (i mean the escape sequence) scio me nihil scire My OpenSource(zlib/libpng License) Engine: http://sourceforge.net/projects/rendertech

        H 1 Reply Last reply
        0
        • H Hauptman n

          but with this method, you give up your portability antoher method is, when you fill up the Console with \n (i mean the escape sequence) scio me nihil scire My OpenSource(zlib/libpng License) Engine: http://sourceforge.net/projects/rendertech

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Portability is often not possible anyway. Say I write a console app to manage the NICs in the machine - unless I add an abstraction layer, managing information on the NICs / in the OS is platform-dependent. Even with the code I gave, one could always abstract that, too. In any case, your idea works, it just isn't technically clearing the screen (this is most notable when you have a larger command/output buffer for your prompt and scroll).

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups