从控制台资源打开EXE或Windows窗体 [英] Opening an EXE or WIndows form from a console resource

查看:149
本文介绍了从控制台资源打开EXE或Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 My.Computer. ''SOMETHING HERE'' (My.Resources.Resource1.WindowsApplication1)
        My.Computer.Audio.Play(My.Resources.Resource1.Entrance_converted, AudioPlayMode.Background)


        ''''''''''''''''''''''''''''''''''''''''
        'Declare Variables as Integer values
        '
        ''''''''''''''''''''''''''''''''''''''''
        Dim Red As Integer
        Dim Blue As Integer
        Dim Green As Integer
        Dim Total As Integer

        ''''''''''''''''''''''''''''''''''''''''
        'Generate a Console which prompts user 
        'for input and allows entry of data by 
        'user
        '
        ''''''''''''''''''''''''''''''''''''''''

        'Input
        Console.ForegroundColor = ConsoleColor.Red
        Console.Write("How many Red Marbles do you have?->")
        Red = Console.ReadLine()
        Console.ForegroundColor = ConsoleColor.Blue
        Console.Write("How many Blue Marbles do you have?->")
        Blue = Console.ReadLine()
        Console.ForegroundColor = ConsoleColor.Green
        Console.Write("How many Green Marbles do you have?->")
        Green = Console.ReadLine()

        ''''''''''''''''''''''''''''''''''''''''
        'Displays how many of each color 
        'Marbles a user has
        '
        ''''''''''''''''''''''''''''''''''''''''
        Total = (Red + Blue + Green)

        'Output
        Console.ForegroundColor = ConsoleColor.Red
        Console.WriteLine("You have, " & Red.ToString() & " Red Marbles, ")
        Console.ForegroundColor = ConsoleColor.Blue
        Console.WriteLine("You have, " & Blue.ToString() & " Blue Marbles, ")
        Console.ForegroundColor = ConsoleColor.Green
        Console.WriteLine("You have, " & Green.ToString() & " Green Marbles, ")
        Console.ResetColor()
        Console.WriteLine("You have a toatl of " & Total.ToString() & " Marbles, wanna play some marbles now?")

        ''''''''''''''''''''''''''''''''''''''''
        ' Console.Read() is used to pause the 
        ' shell screen after entering data and 
        ' allows user to read output without the
        ' shell closing immediately.
        ''''''''''''''''''''''''''''''''''''''''
        Console.Read()
    End Sub

我用粗体和下划线标出的行引起了我一个问题.我有一个独立运行的windowsApplication.exe和一个资源中的Form1.vb.这是带有背景图像的wiindows表单,我希望在控制台应用程序加载时将其打开.我能够做到 这与声音文件.如何调用表格或EXE以便在启动时加载,然后在控制台应用程序加载后停止?

The line i have in bold and underlined is causing me an issue. I have a windowsApplication.exe that works stand alone and a Form1.vb in resources. It is a wiindows form with background image, i want this to open as the console app loads. i was able to do this with the sound file. How do i call either the form or the EXE to load on start then stop once the console app has loaded?

有时答案是如此明显,以至于我看不到它. Sdog

Sometimes the answer is so blindingly obvious i fail to see it. Sdog

推荐答案

 必须先将exe写入硬盘驱动器,然后才能运行它.这是显示如何将exe文件写入硬盘并执行该文件的示例.这是我发的旧帖子,所以您需要更改exe的名称并将代码工作为 您的控制台应用程序.我不使用控制台应用程序,因此我无法真正说出应用程序加载完成后如何停止它.

 You have to write the exe to the hard drive before you can run it. Here is an example that shows how to write the exe file to the hard drive and execute it. It is from an old post i made so you will need to change the exe`s name and work the code into your console app. I don`t use console apps so i can`t really say how you would stop it when your app is finished loading.

Public Class Form1
    Dim MyExe As String = "C:\Test\Command.exe" 'This is the path and name used to save the Exe to the hard drive.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        IO.File.WriteAllBytes(MyExe, My.Resources.Command) 'Save the Exe to the hard drive
        If IO.File.Exists(MyExe) Then
            Process.Start(MyExe) 'If it was successfuly saved then execute it
        End If
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If IO.File.Exists(MyExe) Then IO.File.Delete(MyExe) 'Delete when closing your app if wanted
    End Sub

End Class


这篇关于从控制台资源打开EXE或Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆