Jump to content

Windows Form Application help

- - - - -

  • Please log in to reply
9 replies to this topic

#1
Cybertech44

Cybertech44

    Newbie

  • Members
  • Pip
  • 3 posts
Hey guys i need help, what do i have to add to this code below to make a the button that i added to start a program like .exe in the desired path like "C:\Program Files (x86)\Starcraft 2 Beta\Starcraft2.exe".
I'm using Visual Studio 2008 and 2010 but for now for this problem I'll be using 2008.

Here is the code after i add the first button:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace WinFormApp2
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

}


}
}

What do i need to add to make it start that desired path file?
Thanks for any help.

#2
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts
call win32 api functon ShellExecute(). See MSDN (google) for details.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.

#3
Sky

Sky

    Learning Programmer

  • Members
  • PipPipPip
  • 83 posts
I would just use Process:Start(filepath) since you are already using Forms.

#4
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 298 posts
  • Location:Australia
  • Programming Language:C, C++, PHP, Python, Delphi/Object Pascal, Assembly
  • Learning:Python, Assembly
 tags help :D

I agree with Sky

#5
Cybertech44

Cybertech44

    Newbie

  • Members
  • Pip
  • 3 posts

Sky said:

I would just use Process:Start(filepath) since you are already using Forms.
Doesn't work, build failed: 'Start': identifier not found

#6
Sky

Sky

    Learning Programmer

  • Members
  • PipPipPip
  • 83 posts

Cybertech44 said:

Doesn't work, build failed: 'Start': identifier not found

Sorry, my mistake. It is Process::Start(), not Process:Start(). (Probably, Process.Start() in your case :D)

By the way, do you use intellisense?

EDIT: You can also add process component from toolbox.

#7
Cybertech44

Cybertech44

    Newbie

  • Members
  • Pip
  • 3 posts
Process::Start(), Process:Start() and Process.Start() doesn't work, not sure if i have intellisense but i'm using Visual Studio Ultimate.

#8
Sky

Sky

    Learning Programmer

  • Members
  • PipPipPip
  • 83 posts
but you should use Process component then.

You probably haven't included some needed name spaces for process.

More info:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

You need to include:
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel

Intellisense is microsoft word for Code completion.

Well, If this doesn't work, I would still recommend using process component from toolbox. If you don't really know what I mean, You should see a tool box. Then search for Process and draw it just like you would draw textbox etc. It wouldn't be drawn, however. Instead, It will go to bottom bar. Then, you may edit the property of process component like textbox, label, etc.

Good luck :)

#9
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
I wrote myself exactly the same program (well, for StarCraft 1)

using System.Diagnostics;

public Process proces = new Process();

 private void buttonName_Click(object sender, EventArgs e)    //obviously, change to buttonName to name of your button
{
    proces.StartInfo.FileName = "path\\to\\your\\program";    //remember to use double slashes if your path contains them
    proces.StartInfo.Arguments = "";    // arguments if needed
    proces.Start();
}

A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#10
Shahid@programming

Shahid@programming

    Newbie

  • Members
  • Pip
  • 8 posts
Actually in the .NET framework, there is a managed class called "Process". This class can be used as a static or instance class. This class is found in the
System::Diagnostics
name space.

The "Process" class can start and kill CPU processes and access the active processes information. It also can be use to pass redirect input, output and error input/output information from one process to another.

To make use this class, you have to include at least these name spaces in your project.

using namespace System
using namespace System::Diagnostics

Consult MSDN library to find out how you can use "Process" class.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users