Cov txheej txheem:

Yuav Ua Li Cas Tsim Cov Ntawv Xov Tooj Yooj Yim C#: 7 Cov Kauj Ruam
Yuav Ua Li Cas Tsim Cov Ntawv Xov Tooj Yooj Yim C#: 7 Cov Kauj Ruam

Video: Yuav Ua Li Cas Tsim Cov Ntawv Xov Tooj Yooj Yim C#: 7 Cov Kauj Ruam

Video: Yuav Ua Li Cas Tsim Cov Ntawv Xov Tooj Yooj Yim C#: 7 Cov Kauj Ruam
Video: ib sim cas tsis tsim nyog tsom xyooj 2022 2024, Kaum ib hlis
Anonim
Yuav Ua Li Cas Tsim Cov Ntawv Thov Xov Tooj Yooj Yim C#
Yuav Ua Li Cas Tsim Cov Ntawv Thov Xov Tooj Yooj Yim C#

Nyob zoo, Kuv yog Lukas, nws yog thawj qhov kev qhia kuv. Kuv xav qhia koj yuav tsim phau ntawv xov tooj yooj yim li cas hauv Microsoft Visual Studio siv C#. Nws yog qhov zoo kom muaj qee qhov kev paub pib ntawm kev ua haujlwm ua ntej ua qhov haujlwm no. Cia peb pib. Peb xav tau Microsoft Visual Studio, nws pub dawb rau cov tub ntxhais kawm, koj tuaj yeem tau txais Professional Edition los ntawm MSDNAA. Tshawb nrhiav google kom paub ntau ntxiv. Nov yog qhov peb daim ntawv thov yuav zoo li:

Kauj Ruam 1: Tsim Txoj Haujlwm Tshiab hauv Microsoft Visual Studio

Tsim Txoj Haujlwm Tshiab hauv Microsoft Visual Studio
Tsim Txoj Haujlwm Tshiab hauv Microsoft Visual Studio

Pib Microsoft Visual Studio, thiab tsim qhov Project tshiab, xaiv Windows Forms Application remeber project type is Visual C#. Koj tuaj yeem tso npe rau koj txoj haujlwm txhua yam koj xav tau thiab hloov chaw rau txoj haujlwm yog tias tsis xav tau.

Kauj Ruam 2: Ntxiv Txhua Yam rau Daim Ntawv

Ntxiv txhua yam rau Daim Ntawv
Ntxiv txhua yam rau Daim Ntawv
Ntxiv txhua yam rau Daim Ntawv
Ntxiv txhua yam rau Daim Ntawv

Tam sim no, nws yog Daim Ntawv Tsis Txaus. Wb ntxiv rau nws qee yam khoom siv los ntawm cov cuab yeej raws li pom hauv daim duab. Lawv yog: DataGridView, SaveFileDioalog, OpenFileDialog thiab menuStrip

Kauj Ruam 3: Ntxiv Kab

Ntxiv Kab
Ntxiv Kab

Tom qab ntxiv DataGridView, Peb muaj qhov chaw khoob, nyem txoj cai nas khawm ntawm nws thiab xaiv kho kab.

Kauj Ruam 4: Ua ntej Sau Txoj Cai

Ua ntej Sau Txoj Cai
Ua ntej Sau Txoj Cai

Xyuas kom koj daim ntawv zoo li qhov no thiab DataGridView lub npe "GRID". Koj tuaj yeem teeb nws hauv qhov tsim nyog qhov rai

Kauj Ruam 5: Sau Txoj Cai

Nyem ob zaug ntawm txhua ntu ntawm koj cov ntawv qhia zaub mov, txhawm rau tsim cov xwm txheej, txhua lub sijhawm lub qhov rai nrog tus lej yuav pom, yog li rov qab mus rau nws nrog txhua qhov (Txuag, Qhib, Kaw) Qhov peb xav tau hauv tus lej: ntiag tug tsis muaj dab tsi SaveToolStripMenuItem_Click (tus neeg xa khoom, EventArgs e) {} ntiag tug tsis muaj dab tsi OpenToolStripMenuItem_Click (tus xa khoom, EventArgs e) {} ntiag tug tsis muaj dab tsi CloseToolStripMenuItem_Click (tus xa khoom, EventArgs e) {}

Kauj Ruam 6: Code Code Code…

Nov yog tus lej tag nrho ntawm peb daim ntawv thov nrog cov lus pom tom qab "//" cov xwm txheej: siv System; siv System. Collections. Generic; siv System. ComponentModel; siv System. Data; siv System. Drawing; siv System. Linq; siv System. Ntawv; siv System. IO; // ntxiv siv System. Windows. Forms; siv System. Runtime. Serialization. Formatters. Binary; // ntxiv siv System. Runtime. Serialization; // addnamespace testowa // no kuv lub npe ntawm qhov project {pej xeem ib nrab chav kawm Form1: Daim ntawv {pej xeem Form1 () {InitializeComponent (); } [Serializable] // Nws tso cai rau peb chav kawm kom tau txais kev cawmdim hauv cov ntaub ntawv hauv chav kawm rau pej xeem // Peb chav kawm rau cov ntaub ntawv {pej xeem cov npe lub npe; pej xeem txoj hlua lub npe; pej xeem txoj hlua nroog; pej xeem txoj hlua tooj; } ntiag tug void SaveToolStripMenuItem_Click (tus xa khoom, EventArgs e) {GRID. EndEdit (); SaveFileDialog saveFileDialog1 = tshiab SaveFileDialog (); // Tsim cov ntawv khaws cia sib tham saveFileDialog1. RestoreDirectory = muaj tseeb; // nyeem thiab lim cov ntaub ntawv raw yog (saveFileDialog1. ShowDialog () == DialogResult. OK) {BinaryFormatter formatter = tshiab BinaryFormatter (); FileStream tso tawm = FileStream tshiab (saveFileDialog1. FileName, FileMode. OpenOrCreate, FileAccess. Write); ' int n = GRID. RowCount; cov ntaub ntawv Tus neeg = cov ntaub ntawv tshiab [n - 1]; // Peb muaj cov ntaub ntawv ntau npaum li ntau kab, kab tau ntxiv tsis siv neeg yog li peb ib txwm muaj ib kab ntau dua qhov peb xav tau, yog li n yog tus lej ntawm kab -1 kab tsis ua haujlwm rau (int i = 0; i <n - 1; i ++) {Tus neeg = cov ntaub ntawv tshiab (); // GRID muaj ob tus lej hauv "" thawj tus lej yog tus lej ntawm kab ntawv, thib ob yog tus lej sib txawv ntawm kab ', ntsuas ib txwm pib los ntawm 0' Tus neeg .name = GRID [0, i]. Value. ToString (); Tus neeg .surname = GRID [1, i]. Value. ToString (); Tus neeg .city = GRID [2, i]. Value. ToString (); Tus neeg .number = GRID [3, i]. Value. ToString (); } formatter. Serialize (tso tawm, Tus neeg); tso tawm. Close (); }} ntiag tug tsis muaj dab tsi OpenToolStripMenuItem_Click (tus xa khoom, EventArgs e) // Nyeem Ntawv thiab ntxiv cov ntaub ntawv rau GRID {openFileDialog1 = tshiab OpenFileDialog (); yog (openFileDialog1. ShowDialog () == DialogResult. OK) {BinaryFormatter nyeem ntawv = tshiab BinaryFormatter (); FileStream cov tswv yim = FileStream tshiab (openFileDialog1. FileName, FileMode. Open, FileAccess. Read); cov ntaub ntawv Tus neeg = (cov ntaub ntawv ) nyeem ntawv. Deserialize (tswv yim); GRID. Rows. Clear (); rau (int i = 0; i <Person. Length; i ++) {GRID. Rows. Add (); GRID [0, i]. Value = Tus neeg .name; GRID [1, i]. Value = Tus neeg .surname; GRID [2, i]. Value = Tus neeg .city; GRID [3, i]. Value = Tus neeg .number; }}} ntiag tug tsis muaj dab tsi CloseToolStripMenuItem_Click (tus xa khoom, EventArgs e) {Kaw (); // kaw ib qho app}}}

Kauj ruam 7: Nws Ua tiav. Kuaj Nws

Nyem rau ntawm cov ntawv qhia zaub mov Debug hauv Visual Studio dua li pib Debugging nws yuav tsum ua haujlwm. Sim sim lub app. Kuv paub tseeb tias koj yuav pom qee qhov kab, peb daim ntawv thov yooj yim heev yam tsis muaj kev ruaj ntseg thaum txuag, qhib cov ntaub ntawv, nws tsuas yog ua piv txwv yuav ua li cas thiaj li ua tau daim ntawv thov loj dua. Koj tuaj yeem txhim kho nws, ua koj tus kheej version! Ntxiv qee qhov tshiab, hloov txhua yam koj xav tau. Hmoov zoo!

Pom zoo: