473,324 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,324 developers and data experts.

How to display and hide console in any application

I have been told that it's hard to impossible to display and/or hide a console window from a Forms Application.

I say it is not, however. It's really simple

First, some declares.
Expand|Select|Wrap|Line Numbers
  1.     Declare Function AllocConsole Lib "kernel32" () As Int32
  2.     Declare Function FreeConsole Lib "kernel32" () As Int32
  3.  
Then you just use these functions and the already existing console object, to display, use and hide.

Expand|Select|Wrap|Line Numbers
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         AllocConsole() 'show console
  3.     End Sub
  4.  
  5.  
  6.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  7.         Console.WriteLine(TextBox1.Text)
  8.         'the "Console" object works here, just like it does in a "console application"
  9.     End Sub
  10.  
  11.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  12.         FreeConsole() 'hide console 
  13.     End Sub
It works with the console application too

Expand|Select|Wrap|Line Numbers
  1.     Sub Main()
  2.         Console.WriteLine("line1")
  3.         Console.WriteLine("press Enter to hide for 5 seconds")
  4.         Console.ReadLine()
  5.         FreeConsole() 'send it away
  6.         Threading.Thread.Sleep(5000)
  7.         AllocConsole() 'bring it back
  8.         Console.WriteLine("i'm back")
  9.         Console.WriteLine("goodbye (press enter to leave)")
  10.         Console.ReadLine()
  11.         End
  12.     End Sub
Very simple.
Apr 16 '11 #1
1 19429
Thanks for sharing, very simple and works great!
Jun 4 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Gionni | last post by:
Hello everyone, I'm have a window application, but it is a console application too. I'll try to explain better: if I call the program without parameters the GUI starts. Otherwise it runs as a...
2
by: Yang | last post by:
Hi Is it possible to mask console input in a c# console application? What I mean is: if I entered string "test" in the console, it'll echo "****"(or nothing) instead of the string "test". I've...
1
by: Mullin Yu | last post by:
But, I want is that I can have a Main app that will start a new process or kill one particular or all process. The process will open a console exe. But, I don't want the user to close the console...
2
by: Tee | last post by:
Hi, I am using System.Diagnostics.Process to start a console application, but I don't want the user to see a "black" screen when the console application is running, how can I hide it? Thanks,...
0
by: Manoj Nair | last post by:
Hi, We have a console application which performs a set of tasks on a terminal makes a couple of UDP calls download some info from the server configures the terminal as per the info downloaded...
3
by: inpreet | last post by:
I am trying to build a console application in C#.Net. This application is suppose to run in background without user interaction. How can I hide console to appear?
8
by: Alison | last post by:
Hi, Al I am trying to design a user interface which provides both menus and toolbars for some users to click on whatever they want to do, at the same time, I would like to have a console window...
1
by: JupeMarsInc | last post by:
Hi, I'm using a simple console application project in VC++ (not a window one). my question is, how can I hide the console window,prevent it from popping up when i run my program? Thank you
1
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i have a console application that uses the console to display message status of my process. what's the best way (low impact) to get the messages as they are now into an email? thanks,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.