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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alison

    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
  • Alex Papadimoulis

    #2
    Re: Console Application and Windows Form in VB .Net-Please help!

    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" <anonymous@disc ussions.microso ft.com> wrote in message
    news:6617079C-7A79-4B2B-A566-8D247BDAD1FE@mi crosoft.com...[color=blue]
    > Hi, All
    > I am trying to design a user interface which provides both menus and[/color]
    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.[color=blue]
    >
    > Hope I make my question clear and thanks in advance for any help and hint.
    >
    > Thanks
    > Alison[/color]


    Comment

    • Alison

      #3
      Re: Console Application and Windows Form in VB .Net-Please help!

      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" <anonymous@disc ussions.microso ft.com> wrote in messag
      news:6617079C-7A79-4B2B-A566-8D247BDAD1FE@mi crosoft.com..[color=blue]
      > Hi, Al
      > I am trying to design a user interface which provides both menus an[/color]
      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[color=blue][color=green]
      >> Hope I make my question clear and thanks in advance for any help and hint
      >> Thank[/color]
      > Alison[/color]

      Comment

      • Tom Shelton

        #4
        Re: Console Application and Windows Form in VB .Net-Please help!

        In article <6617079C-7A79-4B2B-A566-8D247BDAD1FE@mi crosoft.com>, Alison wrote:[color=blue]
        > 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[/color]

        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]

        Comment

        • Alison

          #5
          Re: Console Application and Windows Form in VB .Net-Please help!

          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 <6617079C-7A79-4B2B-A566-8D247BDAD1FE@mi crosoft.com>, Alison wrote[color=blue]
          > 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[color=green]
          >> Hope I make my question clear and thanks in advance for any help and hint
          >> Thanks[/color]
          > Aliso[/color]

          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]

          Comment

          • Alison

            #6
            Interaction

            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

            Comment

            • Tom Shelton

              #7
              Re: Interaction

              On Thu, 3 Jun 2004 17:36:01 -0700, Alison wrote:
              [color=blue]
              > 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[/color]

              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]

              Comment

              • Alexandre Moura

                #8
                Re: Console Application and Windows Form in VB .Net-Please help!

                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


                --------------------[color=blue]
                >From: "Alex Papadimoulis" <alexp@papadimo ulis.com>
                >References: <6617079C-7A79-4B2B-A566-8D247BDAD1FE@mi crosoft.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: <OM0aWaaSEHA.21 28@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:[/color]
                cpmsftngxa10.ph x.gbl!TK2MSFTNG XA01.phx.gbl!TK 2MSFTNGP08.phx. gbl!TK2MSFTNGP0 9
                ..phx.gbl[color=blue]
                >Xref: 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[/color]
                on[color=blue]
                >your form that accepts input and does the appropriate thing.
                >
                >-- Alex Papadimoulis
                >
                >"Alison" <anonymous@disc ussions.microso ft.com> wrote in message
                >news:6617079 C-7A79-4B2B-A566-8D247BDAD1FE@mi crosoft.com...[color=green]
                >> Hi, All
                >> I am trying to design a user interface which provides both menus and[/color]
                >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.[color=green]
                >>
                >> Hope I make my question clear and thanks in advance for any help and[/color][/color]
                hint.[color=blue][color=green]
                >>
                >> Thanks
                >> Alison[/color]
                >
                >
                >[/color]

                Comment

                • Dev Guru

                  #9
                  Re: Console Application and Windows Form in VB .Net-Please help!

                  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!

                  Comment

                  Working...