用C#开发Windows应用程序
To develop windows application, we need to using studio and follow some steps:
要開發(fā)Windows應(yīng)用程序 ,我們需要使用studio并遵循一些步驟:
Step 1) First of all we launch visual studio.
步驟1)首先,我們啟動(dòng)Visual Studio。
Step 2) Goto fie menu and select new project.
第2步:轉(zhuǎn)到菜單,然后選擇新項(xiàng)目 。
.minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}Step 3) Now we select "Visual C#" from left panel and select "Windows Forms Application" and give appropriate name to our application. Here I provided name "MyWinApp".
步驟3)現(xiàn)在,我們從左側(cè)面板中選擇“ Visual C#” ,然后選擇“ Windows Forms Application”,并為我們的應(yīng)用程序指定適當(dāng)?shù)拿Q。 在這里,我提供了名稱“ MyWinApp” 。
Step 4) Then A default generated form will appear in our application, like this:
步驟4)然后,默認(rèn)生成的表單將出現(xiàn)在我們的應(yīng)用程序中,如下所示:
.minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}Here we have following things:
這里有以下內(nèi)容:
ToolBox
工具箱
It contains tool to develop the application.
它包含用于開發(fā)應(yīng)用程序的工具。
Solution Explorer
解決方案資源管理器
It contains our project detail; it shows all files related to our project.
它包含我們的項(xiàng)目詳細(xì)信息; 它顯示了與我們項(xiàng)目相關(guān)的所有文件。
Property window
屬性窗口
Using property window we can change the properties of controls which are used in our application.
使用屬性窗口,我們可以更改應(yīng)用程序中使用的控件的屬性。
Building the solution
建立解決方案
We can build our project or solution using build menu or shortcut key: Ctrl + Shift +B.
我們可以使用構(gòu)建菜單或快捷鍵Ctrl + Shift + B來構(gòu)建項(xiàng)目或解決方案。
Execution of Application
執(zhí)行申請(qǐng)
We can execute our application with or without debugging. Here, we use debug menu or it can also be done by using shortcut key: F5 or CTRL+F5.
我們可以在調(diào)試或不調(diào)試的情況下執(zhí)行我們的應(yīng)用程序。 在這里,我們使用調(diào)試菜單 ,也可以使用快捷鍵F5或CTRL + F5來完成 。
通過單擊按鈕控件,設(shè)計(jì)一個(gè)應(yīng)用程序以在MessageBox上顯示“ Hello World”消息 (Design an application to display "Hello World" message on MessageBox by clicking on button control)
First of all, we create a windows application. And then drag and drop a button from toolbox to container form.
首先,我們創(chuàng)建一個(gè)Windows應(yīng)用程序。 然后將一個(gè)按鈕從工具箱拖放到容器窗體。
.minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}We can change the name, color and text etc of any control using property window, here we change our form text to "My First Windows Application" and button text to "Click Me".
我們可以使用屬性窗口更改任何控件的名稱,顏色和文本等,這里我們將表單文本更改為“我的第一個(gè)Windows應(yīng)用程序” ,將按鈕文本更改為“點(diǎn)擊我” 。
Now, we wrote code on button's click event, we can generate sample code for click event by "double click" on the button. Then the generated code will we like this:
現(xiàn)在,我們?cè)诎粹o的click事件上編寫了代碼,我們可以通過“雙擊”按鈕來為click事件生成示例代碼。 然后生成的代碼將如下所示:
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 MyWinApp {public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){}} }Here button1_Click function will use as a click event, here we can write code what we want to do on click event on the button. Now we wrote code to show MessageBox to display "Hello World".
在這里, button1_Click函數(shù)將用作click事件,在這里我們可以編寫代碼,以對(duì)按鈕上的click事件進(jìn)行操作。 現(xiàn)在,我們編寫了代碼來顯示MessageBox來顯示“ Hello World” 。
private void button1_Click(object sender, EventArgs e) {MessageBox.Show("Hello World"); }Execute application using CTRL+F5. Here is the output after clicking on the button "Click Me":
使用CTRL + F5執(zhí)行應(yīng)用程序。 這是單擊“ Click Me”按鈕后的輸出:
翻譯自: https://www.includehelp.com/dot-net/develop-a-windows-application-in-c-sharp.aspx
總結(jié)
以上是生活随笔為你收集整理的用C#开发Windows应用程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: kotlin键值对数组_Kotlin程序
- 下一篇: 操作系统多线程实现_操作系统中的线程实现