• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

C# Question: How do I declare a body?

Joined
Jul 22, 2009
Messages
30 (0.01/day)
Processor AMD Athlon X2 6000+
Motherboard ASUS M2A-MVP
Memory 2GB RAM(OCZ)
Video Card(s) ATI Radeon HD 2600 Pro
Storage 125GB IDE + 500 GB SATA
Display(s) LG Flatron W2242TQ
Case Raidmax Apex
Software Windows 7 and Windows XP
Well I recently began with Visual C# and thought "Wow, this is pretty interesting."
So then I started googling and learned that "Close()" closes the window and MessageBox.Show("Message of Pop up", "Title of Pop up"); ACTUALLY DOES WHATEVER YOU JUST READ.

So yeah, I'm pretty excited about this.

Three things that I can't fix though I've googled it alot are these errors:
Error 1:'UserInterface.Form1.button3_Click(object, System.EventArgs)' must declare a body because it is not marked abstract, extern, or partial
In order of the columns the info is "Form1.cs" - Line 45 - Column 22
Error 2:Program 'C:UsersAdministratorDocumentsVisual Studio 2008ProjectsUserInterfaceUserInterfaceobjDebugUserInterface.exe' has more than one entry point defined: 'UserInterface.Program.Main()'. Compile with /main to specify the type that contains the entry point.
In order of the columns the info is "Program.cs" - Line 14 - Column 21
Error 3:Program 'C:UsersCody SantosDocumentsVisual Studio 2008ProjectsUserInterfaceUserInterfaceobjDebugUserInterface.exe' has more than one entry point defined: 'UserInterface.Form1.ProcessStart.Main(string[])'. Compile with /main to specify the type that contains the entry point.
In order of the columns the info is "Form1.cs" - Line 48 - Column 25

And just for the sake of helping you guys out, below is the actual coding of my project.
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 UserInterface
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Thank you.", "Ok");
Close();
}

private void button1_Click(object sender, EventArgs e)
{
Close();
}

private void label1_Click(object sender, EventArgs e)
{

}

private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void button3_Click(object sender, EventArgs e);
class ProcessStart
{
static void Main(string[] args)
{
Process notePad = new Process();

notePad.StartInfo.FileName = "notepad.exe";
notePad.StartInfo.Arguments = "ProcessStart.cs";

notePad.Start();
}
}
}
}

As you guys can see, I want to try launching different applications through this little application/program that I am trying to do.
All tips will be greatly appreciated.
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.65/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
Error #1:
The semicolon at the end of this line is invalid:
Code:
private void button3_Click(object sender, EventArgs e);

In this context, you must have brackets:
Code:
private void button3_Click(object sender, EventArgs e)
{
}

Error #2 & #3:
You have two "static void Main()" subroutines:
-Error 2 points at the Main in Program.cs.
-Error 3 points at the Main in Form1.cs.

Either you have to get rid of one of those or tell the compiler which to use via the Project properties (right-click on the project and select properties).
 
Joined
Jul 22, 2009
Messages
30 (0.01/day)
Processor AMD Athlon X2 6000+
Motherboard ASUS M2A-MVP
Memory 2GB RAM(OCZ)
Video Card(s) ATI Radeon HD 2600 Pro
Storage 125GB IDE + 500 GB SATA
Display(s) LG Flatron W2242TQ
Case Raidmax Apex
Software Windows 7 and Windows XP
Error #1:
The semicolon at the end of this line is invalid:
Code:
private void button3_Click(object sender, EventArgs e);

In this context, you must have brackets:
Code:
private void button3_Click(object sender, EventArgs e)
{
}

Error #2 & #3:
You have two "static void Main()" subroutines:
-Error 2 points at the Main in Program.cs.
-Error 3 points at the Main in Form1.cs.

Either you have to get rid of one of those or tell the compiler which to use via the Project properties (right-click on the project and select properties).

Well on the internet I just found a work around for the whole "launch-the-app" thing. This only works, however, by using a button and then using this code
Code:
System.Diagnostics.Process.Start("calc.exe");
to launch the application.

Is there anyway I can select the applications I want to launch, kind of like checkboxes and then press a button to launch all of the applications I selected?
What about choosing the application from a drop down menu, then click the button to launch it?
Thanks again
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.65/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
Code:
            FileInfo fi = new FileInfo("PATH TO EXECUTABLE");
            ProcessStartInfo psi = new ProcessStartInfo(fi.FullName, "ARGUMENTS");
            psi.WorkingDirectory = fi.DirectoryName;   // A lot of applications get cranky without doing this.
            Process.Start(psi);

You can do "Process.Start(psi).WaitForExit();" if you want your app to wait until that application closes.


I attached an example that does what you ask. Just look at the code in Main.cs to get an idea of how it works.
 

Attachments

  • Example.zip
    38.9 KB · Views: 287
Last edited:

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.21/day)
Location
Cheeseland (Wisconsin, USA)
You can launch an external application from any method, and by using any type of control (ie. ComboBox, CheckBox, DataGridView, TreeView, Label, etc.) that you want as all of the controls inherit from the base Control class which encapulates (and exposes) the OnClick Event. Depending upon which control you use would depend on the best event to use.
For example
ComboBox : SelectedIndexChanged
CheckBox : Checked or CheckedState
DataGridView : DoubleClick (of the Cell or complete Row)

You could even write your own custum user control to do it. (That's when the fun really starts :D)

Personally, I would decide how I wanted to present the options to the user first. The UI should be intuitive and easy to navigate.
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.65/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
Joined
Jul 22, 2009
Messages
30 (0.01/day)
Processor AMD Athlon X2 6000+
Motherboard ASUS M2A-MVP
Memory 2GB RAM(OCZ)
Video Card(s) ATI Radeon HD 2600 Pro
Storage 125GB IDE + 500 GB SATA
Display(s) LG Flatron W2242TQ
Case Raidmax Apex
Software Windows 7 and Windows XP

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.65/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
It is designed for Combo Boxes, yes. You need the same basic elements (path, arguments) to launch any application. Instead of using the name/index of a Combo Box, just do:
Code:
if (chkMyCheckbox.Checked)
{
  // Same code as Combo Box
}
 
Joined
Jul 22, 2009
Messages
30 (0.01/day)
Processor AMD Athlon X2 6000+
Motherboard ASUS M2A-MVP
Memory 2GB RAM(OCZ)
Video Card(s) ATI Radeon HD 2600 Pro
Storage 125GB IDE + 500 GB SATA
Display(s) LG Flatron W2242TQ
Case Raidmax Apex
Software Windows 7 and Windows XP
It is designed for Combo Boxes, yes. You need the same basic elements (path, arguments) to launch any application. Instead of using the name/index of a Combo Box, just do:
Code:
if (chkMyCheckbox.Checked)
{
  // Same code as Combo Box
}

When I put the same code as Combo Box, I put the code that matches up with the name of the program selected, correct?
Example:
Code:
{ "Calculator", Environment.GetEnvironmentVariable("SystemRoot") + @"\system32\calc.exe", "" },

Also, what is the code for the drop down boxes and when/where do I put them?
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.65/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
I attached an example with check boxes. It has a LaunchApp function to handle launching the applications and also a button click event which checks if the check boxes are checked and taking appropriate actions if they are.

In both examples, most of the code is in Main.cs. If you switch over to designer mode on Main.cs, you can click on the elements to see their properties. In both examples, there really isn't much to see in designer mode except the name. The names coorspond with what is on the Main.cs.


This code:
Code:
{ "Calculator", Environment.GetEnvironmentVariable("SystemRoot") + @"\system32\calc.exe", "" },
...was mostly for organization. By altering that array, you could change which applications are available and how they behave without changing any other code. You could do the same thing for checkboxes but it takes more work (the app would have to create and name checkboxes at runtime to corrospond with the indexes in that array).
 

Attachments

  • Example 2.zip
    36.9 KB · Views: 256
Joined
Jul 22, 2009
Messages
30 (0.01/day)
Processor AMD Athlon X2 6000+
Motherboard ASUS M2A-MVP
Memory 2GB RAM(OCZ)
Video Card(s) ATI Radeon HD 2600 Pro
Storage 125GB IDE + 500 GB SATA
Display(s) LG Flatron W2242TQ
Case Raidmax Apex
Software Windows 7 and Windows XP
Is there anyway I can make the application work over other applications?

Kind of like how On Screen Keyboard runs on/over other applications as well.
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.65/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
On the form in designer view, click on the form title bar, look at the properties toolbox, and set "TopMost" to true.
 
Joined
Jul 22, 2009
Messages
30 (0.01/day)
Processor AMD Athlon X2 6000+
Motherboard ASUS M2A-MVP
Memory 2GB RAM(OCZ)
Video Card(s) ATI Radeon HD 2600 Pro
Storage 125GB IDE + 500 GB SATA
Display(s) LG Flatron W2242TQ
Case Raidmax Apex
Software Windows 7 and Windows XP
On the form in designer view, click on the form title bar, look at the properties toolbox, and set "TopMost" to true.

Thanks, but that only makes the application on top of the others. l want something that would in a way control the other applications. An example of this how On-ScreenKeyboard controls the application selected before it. Like you can open Notepad and then open On-ScreenKeyboard and then click on a 'U' then the U would appear on Notepad.

I want something similar to that.
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.65/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
That is really complex Windows shell stuff and could earn your application the "key logger" label from antiviruses...

You'll have to DllImport user32.dll especially the following two functions:

SendInput
GetAsyncKeyState
 
Top