bitoperations.cs

来自「C#语言高级编成,我多年总结的经验,肯定能让你学到很多」· CS 代码 · 共 388 行 · 第 1/2 页

CS
388
字号
// Fig. O.6: BitOperations.cs
// A class that demonstrates miscellaneous bit operations

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;

namespace UsingBitOperators
{
	/// <summary>
	/// allows user to test bit operators
	/// </summary>
	public class BitOperations : System.Windows.Forms.Form
	{
      private System.Windows.Forms.Label promptLabel;
      private System.Windows.Forms.Label representationLabel;
      private System.Windows.Forms.Label value1Label;
      private System.Windows.Forms.Label value2Label;
      private System.Windows.Forms.Label resultLabel;

      // display bit reprentations
      private System.Windows.Forms.Label bit1Label;
      private System.Windows.Forms.Label bit2Label;
      private System.Windows.Forms.Label resultBitLabel;

      // allow user to perform bit operations
      private System.Windows.Forms.Button andButton;
      private System.Windows.Forms.Button inclusiveOrButton;
      private System.Windows.Forms.Button exclusiveOrButton;
      private System.Windows.Forms.Button complementButton;

      // user inputs two integers
      private System.Windows.Forms.TextBox bit1TextBox;
      private System.Windows.Forms.TextBox bit2TextBox;

      private System.Windows.Forms.TextBox resultTextBox;

      private int value1, value2;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		// default constructor
		public BitOperations()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
         this.promptLabel = new System.Windows.Forms.Label();
         this.representationLabel = new System.Windows.Forms.Label();
         this.value1Label = new System.Windows.Forms.Label();
         this.value2Label = new System.Windows.Forms.Label();
         this.resultLabel = new System.Windows.Forms.Label();
         this.bit1Label = new System.Windows.Forms.Label();
         this.bit2Label = new System.Windows.Forms.Label();
         this.resultBitLabel = new System.Windows.Forms.Label();
         this.bit1TextBox = new System.Windows.Forms.TextBox();
         this.bit2TextBox = new System.Windows.Forms.TextBox();
         this.resultTextBox = new System.Windows.Forms.TextBox();
         this.andButton = new System.Windows.Forms.Button();
         this.inclusiveOrButton = new System.Windows.Forms.Button();
         this.exclusiveOrButton = new System.Windows.Forms.Button();
         this.complementButton = new System.Windows.Forms.Button();
         this.SuspendLayout();
         // 
         // promptLabel
         // 
         this.promptLabel.AutoSize = true;
         this.promptLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.promptLabel.Location = new System.Drawing.Point(64, 8);
         this.promptLabel.Name = "promptLabel";
         this.promptLabel.Size = new System.Drawing.Size(107, 14);
         this.promptLabel.TabIndex = 0;
         this.promptLabel.Text = "Enter two integers:";
         // 
         // representationLabel
         // 
         this.representationLabel.AutoSize = true;
         this.representationLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.representationLabel.Location = new System.Drawing.Point(296, 8);
         this.representationLabel.Name = "representationLabel";
         this.representationLabel.Size = new System.Drawing.Size(111, 14);
         this.representationLabel.TabIndex = 1;
         this.representationLabel.Text = "Bit representations:";
         // 
         // value1Label
         // 
         this.value1Label.AutoSize = true;
         this.value1Label.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.value1Label.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.value1Label.Location = new System.Drawing.Point(16, 40);
         this.value1Label.Name = "value1Label";
         this.value1Label.Size = new System.Drawing.Size(52, 16);
         this.value1Label.TabIndex = 2;
         this.value1Label.Text = "Value 1:";
         // 
         // value2Label
         // 
         this.value2Label.AutoSize = true;
         this.value2Label.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.value2Label.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.value2Label.Location = new System.Drawing.Point(16, 72);
         this.value2Label.Name = "value2Label";
         this.value2Label.Size = new System.Drawing.Size(52, 16);
         this.value2Label.TabIndex = 3;
         this.value2Label.Text = "Value 2:";
         // 
         // resultLabel
         // 
         this.resultLabel.AutoSize = true;
         this.resultLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.resultLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.resultLabel.Location = new System.Drawing.Point(16, 104);
         this.resultLabel.Name = "resultLabel";
         this.resultLabel.Size = new System.Drawing.Size(45, 16);
         this.resultLabel.TabIndex = 4;
         this.resultLabel.Text = "Result:";
         // 
         // bit1Label
         // 
         this.bit1Label.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.bit1Label.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.bit1Label.Location = new System.Drawing.Point(200, 40);
         this.bit1Label.Name = "bit1Label";
         this.bit1Label.Size = new System.Drawing.Size(248, 16);
         this.bit1Label.TabIndex = 5;
         // 
         // bit2Label
         // 
         this.bit2Label.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.bit2Label.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.bit2Label.Location = new System.Drawing.Point(200, 72);
         this.bit2Label.Name = "bit2Label";
         this.bit2Label.Size = new System.Drawing.Size(248, 16);
         this.bit2Label.TabIndex = 6;
         // 
         // resultBitLabel
         // 
         this.resultBitLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.resultBitLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.resultBitLabel.Location = new System.Drawing.Point(200, 104);
         this.resultBitLabel.Name = "resultBitLabel";
         this.resultBitLabel.Size = new System.Drawing.Size(248, 16);
         this.resultBitLabel.TabIndex = 7;
         // 
         // bit1TextBox
         // 
         this.bit1TextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.bit1TextBox.Location = new System.Drawing.Point(88, 40);
         this.bit1TextBox.Name = "bit1TextBox";
         this.bit1TextBox.TabIndex = 8;
         this.bit1TextBox.Text = "";
         // 
         // bit2TextBox
         // 
         this.bit2TextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.bit2TextBox.Location = new System.Drawing.Point(88, 72);
         this.bit2TextBox.Name = "bit2TextBox";
         this.bit2TextBox.TabIndex = 9;
         this.bit2TextBox.Text = "";

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?