473,549 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Console Application and Windows Form in VB .Net-Please help!

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 available in the same form for users to enter commands and display outputs if some prefer to use character based user interface. I would like to implement the user interface in vb .net. Now I have menus and toolbars ready, but do not now how to get a console window run together with menus and toolbars

Hope I make my question clear and thanks in advance for any help and hint

Thanks
Alison
Nov 20 '05 #1
8 18625
Alison,

The Console Application is a determed per project, so you really can't have
a Console run under a window. What you could do, however is add a textbox on
your form that accepts input and does the appropriate thing.

-- Alex Papadimoulis

"Alison" <an*******@disc ussions.microso ft.com> wrote in message
news:66******** *************** ***********@mic rosoft.com...
Hi, All
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 available in the same form for
users to enter commands and display outputs if some prefer to use character
based user interface. I would like to implement the user interface in vb
..net. Now I have menus and toolbars ready, but do not now how to get a
console window run together with menus and toolbars.
Hope I make my question clear and thanks in advance for any help and hint.

Thanks
Alison

Nov 20 '05 #2
Alex

Thanks for the reply.

I am not sure whether you have seen the user interface of Matlab6.0. I try to do a similar one. The matlab user interface seems to have a command window together with menus and toolbars. I thought that command window was a console application. I might be wrong in this though.

Any idea on this

Thanks again
Aliso
----- Alex Papadimoulis wrote: ----

Alison

The Console Application is a determed per project, so you really can't hav
a Console run under a window. What you could do, however is add a textbox o
your form that accepts input and does the appropriate thing

-- Alex Papadimouli

"Alison" <an*******@disc ussions.microso ft.com> wrote in messag
news:66******** *************** ***********@mic rosoft.com..
Hi, Al
I am trying to design a user interface which provides both menus an

toolbars for some users to click on whatever they want to do, at the sam
time, I would like to have a console window available in the same form fo
users to enter commands and display outputs if some prefer to use characte
based user interface. I would like to implement the user interface in v
..net. Now I have menus and toolbars ready, but do not now how to get
console window run together with menus and toolbars
Hope I make my question clear and thanks in advance for any help and hint
Thank

Alison

Nov 20 '05 #3
In article <66************ *************** *******@microso ft.com>, Alison wrote:
Hi, All
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 available in the same form for users to enter commands and display outputs if some prefer to use character based user interface. I would like to implement the user interface in vb .net. Now I have menus and toolbars ready, but do not now how to get a console window run together with menus and toolbars.

Hope I make my question clear and thanks in advance for any help and hint.

Thanks
Alison


I'm playing with this a little bit still... So, far what I have will
only work on 2K up, but it could be modified to use a more general
technique to get the console window handle. I think that if I was to
play with the windows style bits, I could get a more attractive
integration (that's what I'm starting to play with now).

ption Explicit On
Option Strict On

Imports System
Imports System.Runtime. InteropServices
Imports System.Windows. Forms

Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MainMenu1 As System.Windows. Forms.MainMenu
Friend WithEvents StatusBar1 As System.Windows. Forms.StatusBar
Friend WithEvents Panel1 As System.Windows. Forms.Panel
Friend WithEvents MenuItem1 As System.Windows. Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows. Forms.MenuItem
Friend WithEvents Timer1 As System.Windows. Forms.Timer
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Me.MainMenu1 = New System.Windows. Forms.MainMenu
Me.MenuItem1 = New System.Windows. Forms.MenuItem
Me.MenuItem2 = New System.Windows. Forms.MenuItem
Me.StatusBar1 = New System.Windows. Forms.StatusBar
Me.Panel1 = New System.Windows. Forms.Panel
Me.Timer1 = New System.Windows. Forms.Timer(Me. components)
Me.SuspendLayou t()
'
'MainMenu1
'
Me.MainMenu1.Me nuItems.AddRang e(New
System.Windows. Forms.MenuItem( ) {Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.In dex = 0
Me.MenuItem1.Me nuItems.AddRang e(New
System.Windows. Forms.MenuItem( ) {Me.MenuItem2})
Me.MenuItem1.Te xt = "&File"
'
'MenuItem2
'
Me.MenuItem2.In dex = 0
Me.MenuItem2.Te xt = "E&xit"
'
'StatusBar1
'
Me.StatusBar1.L ocation = New System.Drawing. Point(0, 323)
Me.StatusBar1.N ame = "StatusBar1 "
Me.StatusBar1.S ize = New System.Drawing. Size(552, 22)
Me.StatusBar1.T abIndex = 0
Me.StatusBar1.T ext = "StatusBar1 "
'
'Panel1
'
Me.Panel1.AutoS croll = True
Me.Panel1.Dock = System.Windows. Forms.DockStyle .Fill
Me.Panel1.Locat ion = New System.Drawing. Point(0, 0)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing. Size(552, 323)
Me.Panel1.TabIn dex = 1
'
'Timer1
'
Me.Timer1.Enabl ed = True
Me.Timer1.Inter val = 1000
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(552, 345)
Me.Controls.Add (Me.Panel1)
Me.Controls.Add (Me.StatusBar1)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

' this function only works on 2k up...
Private Declare Function GetConsoleWindo w Lib "kernel32" () As
IntPtr
Private Declare Function AllocConsole Lib "kernel32" () As Boolean
Private Declare Function FreeConsole Lib "kernel32" () As Boolean
Private Declare Function SetParent Lib "user32" _
(ByVal hWndChild As IntPtr, _
ByVal hWndNewParent As IntPtr) As IntPtr

Private allocated As Boolean
Private hConsoleWindow As IntPtr
Private hOldParent As IntPtr

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not allocated Then
allocated = AllocConsole()
hConsoleWindow = GetConsoleWindo w()
If Not hConsoleWindow. Equals(IntPtr.Z ero) Then
hOldParent = SetParent(hCons oleWindow, Me.Panel1.Handl e)
End If
End If
End Sub

Private Sub Form1_Closing(B yVal sender As Object, ByVal e As
System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing
If allocated Then
If Not hOldParent.Equa ls(IntPtr.Zero) Then
hOldParent = SetParent(hOldP arent, hConsoleWindow)
End If
FreeConsole()
End If
End Sub

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
Static count As Integer = 0

count += 1
Console.WriteLi ne(count)
End Sub
End Class

I'll post again if I get this working better...
--
Tom Shelton [MVP]
Nov 20 '05 #4
Thanks a lot, Tom. I got the idea now. I will start from what you provided here. I believe I will have more questions concerning this. I will ask for more help later
Thanks agai
Aliso

----- Tom Shelton wrote: ----

In article <66************ *************** *******@microso ft.com>, Alison wrote
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 available in the same form for users to enter commands and display outputs if some prefer to use character based user interface. I would like to implement the user interface in vb .net. Now I have menus and toolbars ready, but do not now how to get a console window run together with menus and toolbars
Hope I make my question clear and thanks in advance for any help and hint
Thanks

Aliso


I'm playing with this a little bit still... So, far what I have wil
only work on 2K up, but it could be modified to use a more genera
technique to get the console window handle. I think that if I was t
play with the windows style bits, I could get a more attractiv
integration (that's what I'm starting to play with now)

ption Explicit On
Option Strict O

Imports Syste
Imports System.Runtime. InteropService
Imports System.Windows. Form

Public Class Form
Inherits System.Windows. Forms.For

#Region " Windows Form Designer generated code

Public Sub New(
MyBase.New(

'This call is required by the Windows Form Designer
InitializeCompo nent(

'Add any initialization after the InitializeCompo nent() cal

End Su

'Form overrides dispose to clean up the component list
Protected Overloads Overrides Sub Dispose(ByVal disposing A
Boolean
If disposing The
If Not (components Is Nothing) The
components.Disp ose(
End I
End I
MyBase.Dispose( disposing
End Su

'Required by the Windows Form Designe
Private components As System.Componen tModel.IContain e

'NOTE: The following procedure is required by the Windows For
Designe
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor
Friend WithEvents MainMenu1 As System.Windows. Forms.MainMen
Friend WithEvents StatusBar1 As System.Windows. Forms.StatusBa
Friend WithEvents Panel1 As System.Windows. Forms.Pane
Friend WithEvents MenuItem1 As System.Windows. Forms.MenuIte
Friend WithEvents MenuItem2 As System.Windows. Forms.MenuIte
Friend WithEvents Timer1 As System.Windows. Forms.Time
<System.Diagnos tics.DebuggerSt epThrough()> Private Su
InitializeCompo nent(
Me.components = New System.Componen tModel.Containe
Me.MainMenu1 = New System.Windows. Forms.MainMen
Me.MenuItem1 = New System.Windows. Forms.MenuIte
Me.MenuItem2 = New System.Windows. Forms.MenuIte
Me.StatusBar1 = New System.Windows. Forms.StatusBa
Me.Panel1 = New System.Windows. Forms.Pane
Me.Timer1 = New System.Windows. Forms.Timer(Me. components
Me.SuspendLayou t(

'MainMenu

Me.MainMenu1.Me nuItems.AddRang e(Ne
System.Windows. Forms.MenuItem( ) {Me.MenuItem1}

'MenuItem

Me.MenuItem1.In dex =
Me.MenuItem1.Me nuItems.AddRang e(Ne
System.Windows. Forms.MenuItem( ) {Me.MenuItem2}
Me.MenuItem1.Te xt = "&File

'MenuItem

Me.MenuItem2.In dex =
Me.MenuItem2.Te xt = "E&xit

'StatusBar

Me.StatusBar1.L ocation = New System.Drawing. Point(0, 323)
Me.StatusBar1.N ame = "StatusBar1 "
Me.StatusBar1.S ize = New System.Drawing. Size(552, 22)
Me.StatusBar1.T abIndex = 0
Me.StatusBar1.T ext = "StatusBar1 "
'
'Panel1
'
Me.Panel1.AutoS croll = True
Me.Panel1.Dock = System.Windows. Forms.DockStyle .Fill
Me.Panel1.Locat ion = New System.Drawing. Point(0, 0)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing. Size(552, 323)
Me.Panel1.TabIn dex = 1
'
'Timer1
'
Me.Timer1.Enabl ed = True
Me.Timer1.Inter val = 1000
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(552, 345)
Me.Controls.Add (Me.Panel1)
Me.Controls.Add (Me.StatusBar1)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

' this function only works on 2k up...
Private Declare Function GetConsoleWindo w Lib "kernel32" () As
IntPtr
Private Declare Function AllocConsole Lib "kernel32" () As Boolean
Private Declare Function FreeConsole Lib "kernel32" () As Boolean
Private Declare Function SetParent Lib "user32" _
(ByVal hWndChild As IntPtr, _
ByVal hWndNewParent As IntPtr) As IntPtr

Private allocated As Boolean
Private hConsoleWindow As IntPtr
Private hOldParent As IntPtr

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not allocated Then
allocated = AllocConsole()
hConsoleWindow = GetConsoleWindo w()
If Not hConsoleWindow. Equals(IntPtr.Z ero) Then
hOldParent = SetParent(hCons oleWindow, Me.Panel1.Handl e)
End If
End If
End Sub

Private Sub Form1_Closing(B yVal sender As Object, ByVal e As
System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing
If allocated Then
If Not hOldParent.Equa ls(IntPtr.Zero) Then
hOldParent = SetParent(hOldP arent, hConsoleWindow)
End If
FreeConsole()
End If
End Sub

Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
Static count As Integer = 0

count += 1
Console.WriteLi ne(count)
End Sub
End Class

I'll post again if I get this working better...
--
Tom Shelton [MVP]
Nov 20 '05 #5
Hi, Tom
I cannot see the counting displayed in the console window. How can I make the console window interactive with the form
Thank
Alison
Nov 20 '05 #6
On Thu, 3 Jun 2004 17:36:01 -0700, Alison wrote:
Hi, Tom,
I cannot see the counting displayed in the console window. How can I make the console window interactive with the form?
Thanks
Alison


Are you running it with Ctrl-F5 or F5? If it is with F5, then it will
probably not work. I'm really not sure this approach is going to work for
you anyway. After playing with it a little more, I can't seem to get the
console to respond correctly...

--
Tom Shelton [MVP]
Nov 20 '05 #7
I tend to agree with Alex (not only because of the name) - you could have a
form that has a single line editable text box and a non editable multiline
textbox to display previously used commands and output, and simulate a
console with that.

Alternatively, you could make your project a console app project, and start
your UI in a separate thread - this will only allow you to provide a
console, and still have a ui, but it isn't a very clean solution - sample
code, for a console app to which I added a windows form:

Module Module1

Sub Main()
'start ui
Dim th As New Threading.Threa d(AddressOf StartMenus)
th.Start()

'do you console stuff here
Dim Leave As Boolean = False
While Not Leave
Dim command As String = Console.ReadLin e()

If LCase(command) = "exit" Then Leave = True

'other processing
End While

'close ui
f.Close()
End Sub

Dim f As New Form1
Sub StartMenus()
'start your ui here
System.Windows. Forms.Applicati on.Run(f)
End Sub
End Module
--------------------
From: "Alex Papadimoulis" <al***@papadimo ulis.com>
References: <66************ *************** *******@microso ft.com>
Subject: Re: Console Application and Windows Form in VB .Net-Please help!
Date: Thu, 3 Jun 2004 16:08:30 -0400
Lines: 25
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <OM************ **@TK2MSFTNGP09 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: 208-40-31-42.corecomm.net 208.40.31.42
Path: cpmsftngxa10.ph x.gbl!TK2MSFTNG XA01.phx.gbl!TK 2MSFTNGP08.phx. gbl!TK2MSFTNGP0 9
..phx.gblXref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:207496
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

Alison,

The Console Application is a determed per project, so you really can't have
a Console run under a window. What you could do, however is add a textbox onyour form that accepts input and does the appropriate thing.

-- Alex Papadimoulis

"Alison" <an*******@disc ussions.microso ft.com> wrote in message
news:66******* *************** ************@mi crosoft.com...
Hi, All
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 available in the same form for
users to enter commands and display outputs if some prefer to use character
based user interface. I would like to implement the user interface in vb
.net. Now I have menus and toolbars ready, but do not now how to get a
console window run together with menus and toolbars.

Hope I make my question clear and thanks in advance for any help and hint.
Thanks
Alison



Nov 20 '05 #8
Alex:

Check this product out. http://www.neopixell.com/products.php

I am not assoicated with this company in form or shape but thought this
product might be of help to you. It offers a console "window" from a
standard application.

Let us know what you think of this product.

Dev Guru

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5364
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component...
2
10975
by: Chris | last post by:
Hi, Currently, I have a console application written in C# and an unmanaged legacy DLL written in VC++ 6.0. In the DLL's previous application, when an event occurs in the DLL, a windows message would be sent to the host GUI application via PostMessage to WM_USER + X. The GUI application would then execute a function to retrieve data from...
1
2737
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 windows by themselves, and force them to use the Main app. If I use Windows Services, I'm not sure can I create one dynamically, and then kill...
1
2572
by: James Carnley | last post by:
I am learning how to use windows forms and I have come across a small problem. Whenever I run my program it opens a console window before launching the windows form. The console doesnt go away until the program exits. When you use VS.net to make a windows application it makes a form without a console and I dont know why. What specifies...
1
1829
by: Clifton Griffin | last post by:
Ok, I have a proxy server written in c#. Because I'm maintaning two versions (a console application for debugging and a windows service for deployment) I got the console application working, then I added a service and wrote the service. However, I can't seem to figure out a way to actually compile and use the service. It is in the...
3
15016
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?
3
1957
by: Dean Slindee | last post by:
I have a exception handling class that could be called from either a windows project app or a console project app. Is there any way for this class to determine which type of app called it without sending an window/console parameter from either app? Thanks, Dean Slindee
3
2306
by: JohnH | last post by:
Does any one now how to create a .net service thet when run from the command line with say a -D argument will run as a console app and be able to output to that console window. The same .exe would start as a normal service wihout the -D argument and require use of the NET START command or other.
4
3101
by: ano | last post by:
I have a console application and a lot of Console.WriteLine(). Now I want to convert it to Windows Form Application. Is it possible to getting all of the console messages to Form.Textbox without changing every Console.WriteLine()? Thank you in advance. ano
15
2772
by: Michael C | last post by:
Is it possible to have an app that is both a console app and a windows app? If there are no command line switches then it will run as a console app, if there are command line switches then it will be a windows app. If I make it a windows app then I can't write to the console. If I make it a console app then it starts a console if the user runs...
0
7551
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6084
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5396
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5118
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3524
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1971
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.