Having a button link to another application -help?

This is a discussion on Having a button link to another application -help? within the C# Programming forums, part of the General Programming Boards category; I'm working in application and I need some help but dono if its possible? I have a button in application ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    33

    Having a button link to another application -help?

    I'm working in application and I need some help but dono if its possible?
    I have a button in application form, and i want that button to link or open up another form.

    So... I have 1 application form with a button. A user clicks the button, and brings him to another application.

    Any ideas?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    If the other application is not already running, you can start it yourself. http://blogs.msdn.com/csharpfaq/arch...01/146375.aspx

    If it is already running, then the problem is a bit harder. As I've never really used C#, I don't know how it would be done. You'd probably have to get the process ID of the application you want to switch to and set the focus to that window.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    33
    Thx for the link. I got much closer now, although thats still not really what I was looking for...
    Ill be more specific... I have 1 big application. In the application, i got two forms... The main form which contains the button to open up the second form(which is in the same application). So when i build the whole application, im left with one .exe which runs both; the form1 and form2, but form2 is only run or activated(popped up) by the form1 button.

    Another alternative which i would find accept full but have no idea in doing this... If i do use the link info:
    Example 1. Running a command line application, without concern for the results:
    Code:
    private void simpleRun_Click(object sender, System.EventArgs e){
     System.Diagnostics.Process.Start(@"C:\listfiles.bat");
    }
    I could have two seperate .exe's(form1 and form2). Have form1 normally ran, and have form2 run by the button, which i tested and works. But, now the problem is if... what if i move the files? or i give the files to someone else? Then the link doesnt work... If it could be possible ... I was thinking having a main directory/folder, (Application) with all files inside of it and have the program only recall that folder... In other words, have the link/url only say or look in... '\application\...' itself... that way the folder can be moved anywhere in the comp, and the program can still work nicely as it only cares whats inside of the folder, not where it is located on the computer's hard drive.

    Any ideas?

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    I'm sure you can use relative paths with System.Diagnostics.Process.Start(). Like
    Code:
    System.Diagnostics.Process.Start(@"listfiles.bat");
    which would run listfiles.bat in the current directory. Then you could move the actual program anywhere.

    But it sounds like you have a problem that would be easier to solve internally. Why don't you just call the function or make an instance of the class or whatever from form1 to instantiate form2?

    Maybe you'd better wait for a C# programmer . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    33
    Hmm, nope... changing it to something like ..
    Code:
    System.Diagnostics.Process.Start(@"listfiles.bat");
    didnt work...said file path not found.

    I tried doing this ... but didnt work either ... This is the application with form1 and form2
    Code:
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new form2());

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Quote Originally Posted by Diablo02 View Post
    Hmm, nope... changing it to something like ..
    Code:
    System.Diagnostics.Process.Start(@"listfiles.bat");
    didnt work...said file path not found.
    It should, if you moved listfiles.bat into the same directory as your program.

    If not, try a different function. There's no way C# would force you to specifiy the full path to an executable. Or if it did, it would provide a function to get the current path.

    Or try ".\listfiles.bat".
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    33
    Oh, oops, i mis typed the actual path.. It does work.
    Code:
    System.Diagnostics.Process.Start(@"listfiles.bat");
    Thx for the help.

  8. #8
    Registered User
    Join Date
    Aug 2007
    Posts
    33
    Another thing came up... how would i specify a random coordinate (random x, random y) for the window to open at?

  9. #9
    mog
    mog is offline
    Sasquatch mog's Avatar
    Join Date
    Dec 2006
    Location
    Caves of Narshe
    Posts
    16
    Two forms in the same program with one button to open the other with position "Centerscreen".

    Code:
    public class A : Forms
    {
        public A()
        {
            Button button = new Button("PushMe");
            button.Clicked += new EventHandler(Button_Push);
            button.Show();
        }
        
        private void Button_Push(object sender, EventArgs e)
        {
            B f = new B();
            f.Show();
        }
    }
    
    public class B : Forms
    {
        public B()
        {
            StartPosition = FormStartPosition.CenterScreen;
            Label l = new Label();
            l.Text = "Im mr. B";
            l.Show();
        }
    }

  10. #10
    Registered User
    Join Date
    Aug 2007
    Posts
    33
    thx man!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Application.Exit
    By George2 in forum C# Programming
    Replies: 8
    Last Post: 05-02-2008, 02:24 AM
  2. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 11:32 AM
  3. dynamically link my DLL to an application
    By Maranello in forum C++ Programming
    Replies: 0
    Last Post: 04-20-2005, 07:52 AM
  4. Undefined Structure in Link List
    By _Cl0wn_ in forum C Programming
    Replies: 1
    Last Post: 03-22-2003, 04:57 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21