StartIf you want to open an existing project, pick the project with the (solution) file extension as follows. Otherwise, go to the next step.🡆All Programs🡆Visual Studio 2019
C:\C#-workspace\WindowsFormsApp1\Form1.cs
|
using System;
using System.Windows.Forms;
namespace WindowsFormsApp1 {
public partial class Form1 : Form {
public Form1( ) {
InitializeComponent();
}
public static string sendtext = "";
private void Button1_Click( object sender, EventArgs e ) {
sendtext = textBox1.Text;
Form2 frm = new Form2( );
frm.Show( );
this.Visible = false;
}
private void Button2_Click( object sender, EventArgs e ) {
Application.Exit( );
}
}
}
|
InitializeComponent loads the compiled page of a component.
Just leave it there.
This program is to send the entered name to the form, , which displays the name.
For how to write a C# program, check C# Tutorial.
Project 🡆 Add Windows Form...
C:\C#-workspace\WindowsFormsApp1\Form2.cs
|
using System;
using System.Windows.Forms;
namespace WindowsFormsApp1 {
public partial class Form2 : Form {
public Form2( ) {
InitializeComponent( );
}
private void Form2_Load( object sender, EventArgs e ) {
label1.Text = "Welcome to C#, " + Form1.sendtext;
}
private void Button1_Click( object sender, EventArgs e ) {
this.Visible = false;
Form1 frm = new Form1( );
frm.Show( );
}
}
}
|
Note that the or method may not work if it is entered manually. Instead, double click the form of the design view and use the template generated by it.
Build 🡆 Build Solution
Unable to copy file "obj\Release\WindowsFormsApp4.exe" to "bin\Release\WindowsFormsApp4.exe". The process cannot access the file 'bin\Release\WindowsFormsApp1.exe' because it is being used by another process.WindowsFormsApp1”most likely because the previous execution did not exit formally. To solve this problem, use the Windows Task Manager (++) to end the background processes.
Debug 🡆 Start Without Debugging
One example of execution results is shown as follows:
|
Submit 🡆🡄 Home
|
|
|
“They say you shouldn’t say anything about the dead unless it’s good. He’s dead. Good.” — Moms Mabley |