• 大小: 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个文件信息

评论

共有 条评论