473,287 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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 18580
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*******@discussions.microsoft.com> wrote in message
news:66**********************************@microsof t.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*******@discussions.microsoft.com> wrote in messag
news:66**********************************@microsof t.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**********************************@microsoft.co m>, 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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.components = New System.ComponentModel.Container
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.SuspendLayout()
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New
System.Windows.Forms.MenuItem() {Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New
System.Windows.Forms.MenuItem() {Me.MenuItem2})
Me.MenuItem1.Text = "&File"
'
'MenuItem2
'
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "E&xit"
'
'StatusBar1
'
Me.StatusBar1.Location = New System.Drawing.Point(0, 323)
Me.StatusBar1.Name = "StatusBar1"
Me.StatusBar1.Size = New System.Drawing.Size(552, 22)
Me.StatusBar1.TabIndex = 0
Me.StatusBar1.Text = "StatusBar1"
'
'Panel1
'
Me.Panel1.AutoScroll = True
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel1.Location = New System.Drawing.Point(0, 0)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(552, 323)
Me.Panel1.TabIndex = 1
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.Interval = 1000
'
'Form1
'
Me.AutoScaleBaseSize = 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 GetConsoleWindow 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not allocated Then
allocated = AllocConsole()
hConsoleWindow = GetConsoleWindow()
If Not hConsoleWindow.Equals(IntPtr.Zero) Then
hOldParent = SetParent(hConsoleWindow, Me.Panel1.Handle)
End If
End If
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If allocated Then
If Not hOldParent.Equals(IntPtr.Zero) Then
hOldParent = SetParent(hOldParent, hConsoleWindow)
End If
FreeConsole()
End If
End Sub

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

count += 1
Console.WriteLine(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**********************************@microsoft.co m>, 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
InitializeComponent(

'Add any initialization after the InitializeComponent() 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.Dispose(
End I
End I
MyBase.Dispose(disposing
End Su

'Required by the Windows Form Designe
Private components As System.ComponentModel.IContaine

'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.Diagnostics.DebuggerStepThrough()> Private Su
InitializeComponent(
Me.components = New System.ComponentModel.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.SuspendLayout(

'MainMenu

Me.MainMenu1.MenuItems.AddRange(Ne
System.Windows.Forms.MenuItem() {Me.MenuItem1}

'MenuItem

Me.MenuItem1.Index =
Me.MenuItem1.MenuItems.AddRange(Ne
System.Windows.Forms.MenuItem() {Me.MenuItem2}
Me.MenuItem1.Text = "&File

'MenuItem

Me.MenuItem2.Index =
Me.MenuItem2.Text = "E&xit

'StatusBar

Me.StatusBar1.Location = New System.Drawing.Point(0, 323)
Me.StatusBar1.Name = "StatusBar1"
Me.StatusBar1.Size = New System.Drawing.Size(552, 22)
Me.StatusBar1.TabIndex = 0
Me.StatusBar1.Text = "StatusBar1"
'
'Panel1
'
Me.Panel1.AutoScroll = True
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel1.Location = New System.Drawing.Point(0, 0)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(552, 323)
Me.Panel1.TabIndex = 1
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.Interval = 1000
'
'Form1
'
Me.AutoScaleBaseSize = 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 GetConsoleWindow 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not allocated Then
allocated = AllocConsole()
hConsoleWindow = GetConsoleWindow()
If Not hConsoleWindow.Equals(IntPtr.Zero) Then
hOldParent = SetParent(hConsoleWindow, Me.Panel1.Handle)
End If
End If
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If allocated Then
If Not hOldParent.Equals(IntPtr.Zero) Then
hOldParent = SetParent(hOldParent, hConsoleWindow)
End If
FreeConsole()
End If
End Sub

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

count += 1
Console.WriteLine(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.Thread(AddressOf StartMenus)
th.Start()

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

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.Application.Run(f)
End Sub
End Module
--------------------
From: "Alex Papadimoulis" <al***@papadimoulis.com>
References: <66**********************************@microsoft.co m>
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.public.dotnet.languages.vb
NNTP-Posting-Host: 208-40-31-42.corecomm.net 208.40.31.42
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP09
..phx.gblXref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.languages.vb:207496
X-Tomcat-NG: microsoft.public.dotnet.languages.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*******@discussions.microsoft.com> wrote in message
news:66**********************************@microso ft.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
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...
2
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...
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...
1
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...
1
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,...
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?
3
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...
3
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...
4
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...
15
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
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...

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.