(C#) Chapter - 2
(C#) Chapter - 2
If you create another class and give it a static method named
Main, Visual Studio cannot figure out which one to launch.
You can resolve that problem in a couple ways.
1
2
5
1. Solution Explorer—This area lists the files associated with the project.
Double-click a file to open it in the designer area.
2. Designer—This area contains designers that enable you to edit different
kinds of files. For example, the Code Editor enables you to edit C# code,
and the Form Designer enables you edit forms. Figure shows the Form
Designer editing the user interface for the form defined by the file
Form1.cs.
3. Toolbox—While you are editing a form, you can click a control in the
Toolbox to select it. Then you can click and drag to place an instance of
that control on the form.
4. Properties—If you select a control in the Window Designer, this area
displays that control’s properties and enables you to edit them. In Figure,
the form is selected, so this area is showing the form’s properties. For
example, you can see in the Properties Window that the form’s Text
property is set to Form1. In the Form Designer, you can see that the form
displays its text at the top.
5. Other windows—This area typically holds other windows such as the
Error List and Output Window. The program shown in Figure does not
currently have any errors, so the ErrorList is empty.
lblInformation.Text += "\n";
using System;
lblInformation.Text += "LastName - " +
using System.Collections.Generic; txtLastName.Text;
using System.ComponentModel; txtFirstName.Text = "";
using System.Data; txtLastName.Text = "";
using System.Drawing; btnClick.Text = "Finished!!";
using System.Linq; }
using System.Text; private void btnClear_Click(object sender,
using System.Threading.Tasks; EventArgs e)
using System.Windows.Forms; {
txtFirstName.Text = "";
namespace WindowsFormsApplication1 txtLastName.Text = "";
lblInformation.Text = "";
{ }
public partial class Form1 : Form
{ private void btnExit_Click(object sender, EventArgs
public Form1() e)
{ {
System.Environment.Exit(0);
InitializeComponent();
} }
private void btnClick_Click(object sender, EventArgs
} e)
{ }
lblInformation.Text= "";
lblInformation.Text += "FirstName - " + txtFirstName.Text;
WPF Applications
Creating a WPF application is similar to creating a Windows Forms
application. Select File ➪ New Project, select the WPF Application template,
and enter a project name, enter a project location. Then click OK to create the
project.
The center of Visual Studio contains a Window Designer similar to the Form
Designer in Window Form. The Solution Explorer and Properties Window are
on the right. (Although, there are many differences between the two versions of
the Properties Window.) The Error List appears at the bottom of both figures.
One notable difference between the two displays is the XAML code window
at the bottom of the Window Designer.
Use the Properties Window to set the button’s properties. Note that in WPF
applications the button’s Content property determines its caption or other
contents, not the Text property used by a Windows Forms button.
WPF Applications
using System;
using System.Collections.Generic; private void ClickMeButton_Click(object sender,
using System.Linq; RoutedEventArgs e)
using System.Text; {
using System.Threading.Tasks; lblInfo.Content = "";
using System.Windows;
using System.Windows.Controls; if (Apple.IsChecked==true)
using System.Windows.Data; {
using System.Windows.Documents; lblInfo.Content += "Apple Fruit\n";
using System.Windows.Input; }
using System.Windows.Media;
using System.Windows.Media.Imaging; if (Orange.IsChecked == true)
using System.Windows.Navigation; {
using System.Windows.Shapes; lblInfo.Content += "Orange Fruit\n";
namespace WpfApplication1 }
{
public partial class MainWindow : Window if (Watermelon.IsChecked == true)
{ {
public MainWindow() lblInfo.Content += "Watermelon Fruit";
{ }
InitializeComponent(); }
} }
}
Difference Between Window Form
Application and WPF Application
• WPF is a graphical subsystem that renders user interfaces in Windows
based applications. Window Form is the graphical API that provides
access to native Microsoft Windows interface elements.