Question Backward button to go back to form from opened .exe program.

Kevax

New member
Joined
Jun 20, 2012
Messages
3
Location
Sweden
Programming Experience
Beginner
Hi!

I am currently working on a program that has several buttons in it lined up. Each button goes to different applications (.exe programs). The program I am making is suppose to be a fullscreen program and won't let you see any of Windows when it's running. Therefore I want to make a "back" button that always stays on top of any application and when I push it it will take me back to my WindowsForm (startpage of the program). Any ideas? :crap:

I am also wondering if you can make it so all .exe programs only can run ONCE. So if I press one of the buttons saying "open notepad" I want it to work so it can't open Notepad once again making it two notepads open. Just go back to the first Notepad opened.

Thank you for your time! // Kevin.
 
With regards to the first question, would a keyboard shortcut maybe be a better option, so that you don;t have to have a distracting button floating around? If you think so then you should look for examples of using the RegisterHotKey API.

As for the second question, all you need is a Boolean variable. You set it the first time you run a program and check it each time. You might even use the Enabled property of the Button, which is type Boolean, in which case the user simply can't press the Button.
 
First, thx for answering so fast. I think I will go with the hotkey solution for my "go back" problem :) But I don't really understand the meaning of a boolean variable... I am very new to coding but is always eager to learn and often do it fast. I also have to mention that I am doing this is Visual Basic 2010 code, not C# or C++. I tried to change the enable setting for one of my buttons to false and it didn't work anymore which is very obvious... but I don't understand how to make a boolean veriable to make my .exe programs not open twice. Because I want to push the button to open desired program but I don't want it to open in more then one instance.

I don't want it to open like if someone opened Chrome for 10times over and the computer hangs itself. I hope I make some kind of sense here. I am very glad that you are trying to help me. Thx!
 
You presumably know what a variable is. The Boolean data type can have the values True and False. Whenever you use an If statement you are testing a Boolean expression and doing something if it evaluates to True. You could use a Boolean variable for each program. Set it to True initially and then set it to False when you run the program. You can then check it and only run the program if it's True.

As I said though, you may be better off just using the Enabled property of the Button. If you set Enabled to False the first time it's clicked then it can't be clicked again. If the Button can't be clicked then the program can't be run, therefore there's no need for anything else.
 
My code looks like this right now for opening one of the programs, where do I write in the boolean code?

Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Process.Start("C:\Kartex\Kartex.exe")
End Sub

Sry for being so slow on this.. but I really don't get it to work. I've read some solutions on other forums and tutorials but it dosen't work.
 
Toggle with a Boolean variable

The Boolean variable in an event will only work once. As soon as the event ends, it will go back to the original value, since it is no longer in memory. What you need to do is declare the variable as Static. That way it will remain in memory and you can use the button as a toggle along with the logical Not operator. Here is an example:

VB.NET:
	Private Sub btnToggle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToggle.Click
		Static onoff As Boolean
		onoff = Not onoff
		If onoff = True Then
			MessageBox.Show("ON")
		Else
			MessageBox.Show("OFF")
		End If
	End Sub

However, if you only want the code to work once, then there is no need for the Static declaration or the Not toggle. The default of the Boolean variable is False, and when the button is clicked, change it to True.
 
Last edited:
Hi Kevax,

Dunno if I can help but I made a program a while back that needed to kill one certain process, but on a server multiple users used there own process, so I never knew which one I was killing, so I had to start the process from my application, and stored the sessionID, so I knew which process with SessionID i had to kill.

So for you I think if your application starts notepad you could retrieve its processID, and than you could simply check if that processID existed, to either go back to notepad you started or if it doesn't exist start it again.

Gunze
 
Back
Top