-
大小: 721.46 KB文件類型: .rar金幣: 2下載: 0 次發布日期: 2024-07-28
- 語言: C#
- 標簽: 101??C#??WindowsForms??微軟??
資源簡介
這是微軟給的類似于SDK中事例代碼的程序,總共101個,這是Windows Forms篇,總共四個。
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
namespace?AsynchronousTasks
{
????public?partial?class?MainForm?:?Form
????{
????????private?System.ComponentModel.BackgroundWorker?backgroundCalculator;
????????public?MainForm()
????????{
????????????InitializeComponent();
????????????//?Prepare?the?background?worker?for?asynchronous?prime?number?calculation
????????????backgroundCalculator?=?new?BackgroundWorker();
????????????//?Specify?that?the?background?worker?provides?progress?notifications
????????????backgroundCalculator.WorkerReportsProgress?=?true;
????????????//?Specify?that?the?background?worker?supports?cancellation
????????????backgroundCalculator.WorkerSupportsCancellation?=?true;
????????????//?The?DoWork?event?handler?is?the?main?work?function?of?the?background?thread
????????????backgroundCalculator.DoWork?+=?new?DoWorkEventHandler(backgroundCalculator_DoWork);
????????????//?Specify?the?function?to?use?to?handle?progress?notifications
????????????backgroundCalculator.ProgressChanged?+=?new?ProgressChangedEventHandler(backgroundCalculator_ProgressChanged);
????????????//?Specify?the?function?to?run?when?the?background?worker?finishes
????????????//?There?are?three?conditions?possible?that?should?be?handled?in?this?function:
????????????//?1.?The?work?completed?successfully
????????????//?2.?The?work?aborted?with?errors
????????????//?3.?The?user?cancelled?the?process
????????????backgroundCalculator.RunWorkerCompleted?+=?new?RunWorkerCompletedEventHandler(backgroundCalculator_RunWorkerCompleted);
????????????updateStatus(String.Empty);
????????}
????//?This?region?implements?calculating?primes?in?a?synchronous?fashion
????#region?Synchronous?calculation
????????//?Synchronously?calculate?the?next?prime?number?
????????//?starting?with?a?specified?number.
????????private?int?getNextPrimeSync(int?start)
????????{
????????????int?percentComplete?=?0;
????????????start++;
????????????while?(!isPrime(start))
????????????{
????????????????//?start?was?not?prime.??Try?next?number?higher.
????????????????start++;
????????????????//?Report?progress
????????????????percentComplete++;
????????????????//?With?prime?number?calculation?there?is?no?way?to?determine
????????????????//?how?far?along?you?are?so?simply?move?the?progress?bar
????????????????//?and?reset?as?needed
????????????????updateProgress(percentComplete?%?100);
????????????}
????????????return?start;
????????}
????????private?void?nextPrimeButton_Click(object?sender?EventArgs?e)
????????{
????????????updateStatus(“Calculating...“);
int?start;
Int32.TryParse(textBoxPrime.Text?out?start?);
if?(start?==?0)
{
reportError(“The?number?must?be?a?valid?integer“);
}
else
{
try
{
int?prime?=?getNextPrimeSync(start);
reportPrime(prime)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3037??2005-06-29?12:28??Windows?Forms\AsynchronousTasks\AsynchronousTasks\AsynchronousTasks.csproj
?????文件????????173??2005-06-29?12:28??Windows?Forms\AsynchronousTasks\AsynchronousTasks\AsynchronousTasks.csproj.user
?????文件??????24576??2007-08-18?15:40??Windows?Forms\AsynchronousTasks\AsynchronousTasks\bin\Debug\AsynchronousTasks.exe
?????文件??????32256??2007-08-18?15:40??Windows?Forms\AsynchronousTasks\AsynchronousTasks\bin\Debug\AsynchronousTasks.pdb
?????文件???????5632??2005-09-23?06:56??Windows?Forms\AsynchronousTasks\AsynchronousTasks\bin\Debug\AsynchronousTasks.vshost.exe
?????目錄??????????0??2007-08-18?15:34??Windows?Forms\AsynchronousTasks\AsynchronousTasks\bin\Debug
?????目錄??????????0??2007-08-18?15:33??Windows?Forms\AsynchronousTasks\AsynchronousTasks\bin
?????文件???????8168??2007-08-18?15:40??Windows?Forms\AsynchronousTasks\AsynchronousTasks\Form1.cs
?????文件???????7828??2007-08-18?15:40??Windows?Forms\AsynchronousTasks\AsynchronousTasks\Form1.Designer.cs
?????文件???????6017??2007-08-18?15:40??Windows?Forms\AsynchronousTasks\AsynchronousTasks\Form1.resx
?????文件????????341??2007-08-18?15:41??Windows?Forms\AsynchronousTasks\AsynchronousTasks\obj\AsynchronousTasks.csproj.FileList.txt
?????文件????????842??2007-08-18?15:40??Windows?Forms\AsynchronousTasks\AsynchronousTasks\obj\Debug\AsynchronousTasks.csproj.GenerateResource.Cache
?????文件??????24576??2007-08-18?15:40??Windows?Forms\AsynchronousTasks\AsynchronousTasks\obj\Debug\AsynchronousTasks.exe
?????文件????????180??2007-08-18?15:40??Windows?Forms\AsynchronousTasks\AsynchronousTasks\obj\Debug\AsynchronousTasks.MainForm.resources
?????文件??????32256??2007-08-18?15:40??Windows?Forms\AsynchronousTasks\AsynchronousTasks\obj\Debug\AsynchronousTasks.pdb
?????文件????????180??2007-08-18?15:34??Windows?Forms\AsynchronousTasks\AsynchronousTasks\obj\Debug\AsynchronousTasks.Properties.Resources.resources
?????目錄??????????0??2007-08-18?15:33??Windows?Forms\AsynchronousTasks\AsynchronousTasks\obj\Debug\TempPE
?????目錄??????????0??2007-08-18?15:40??Windows?Forms\AsynchronousTasks\AsynchronousTasks\obj\Debug
?????目錄??????????0??2007-08-18?15:34??Windows?Forms\AsynchronousTasks\AsynchronousTasks\obj
?????文件????????542??2005-06-29?12:28??Windows?Forms\AsynchronousTasks\AsynchronousTasks\Program.cs
?????文件???????1281??2005-06-29?12:28??Windows?Forms\AsynchronousTasks\AsynchronousTasks\Properties\AssemblyInfo.cs
?????文件???????2368??2005-06-29?12:28??Windows?Forms\AsynchronousTasks\AsynchronousTasks\Properties\Resources.Designer.cs
?????文件???????5612??2005-06-29?12:28??Windows?Forms\AsynchronousTasks\AsynchronousTasks\Properties\Resources.resx
?????文件???????1119??2005-06-29?12:28??Windows?Forms\AsynchronousTasks\AsynchronousTasks\Properties\Settings.Designer.cs
?????文件????????249??2005-06-29?12:28??Windows?Forms\AsynchronousTasks\AsynchronousTasks\Properties\Settings.settings
?????目錄??????????0??2007-08-18?10:12??Windows?Forms\AsynchronousTasks\AsynchronousTasks\Properties
?????文件????????900??2005-06-29?12:28??Windows?Forms\AsynchronousTasks\AsynchronousTasks\README.htm
?????目錄??????????0??2007-08-18?15:40??Windows?Forms\AsynchronousTasks\AsynchronousTasks
?????文件????????940??2005-06-29?12:28??Windows?Forms\AsynchronousTasks\AsynchronousTasks.sln
????..A..H.?????12288??2007-08-18?15:41??Windows?Forms\AsynchronousTasks\AsynchronousTasks.suo
............此處省略367個文件信息
- 上一篇:c#編寫的連連看程序
- 下一篇:C#異構數據庫轉換工具源碼
評論
共有 條評論