⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 MATLAB C# Book. This book is a great tutorial for C# programmers who use MATLAB to develop applicati
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using UtilityMatlabCompilerVer4 ;

namespace Multiple
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public TextBox[,] arrTextBoxMatrixA ;
		public double[,] db_MatrixA  ;

		public TextBox[,] arrTextBoxMatrixB ;
		public double[,] db_MatrixB  ;

		public TextBox[,] arrTextBoxMatrixC ;
		public double[,] db_MatrixC  ;

		public int m_numRowMatricATextBox ;
		public int m_numColMatricATextBox ;

		public int m_tbLength ;
		public int m_tbHeight ;

		public Point m_startPoint = new Point() ;
		public Point m_startPointMatrixB = new Point() ;
		public Point m_startPointMatrixC = new Point() ;

		int m_numRowMatrixBTextBox ;
		int m_numColMatrixBTextBox ;

		int m_FormLength ;
		int m_FormHeight ;

		int m_numRowMatriCTextBox ;
		int m_numColMatriCTextBox ;

		private System.Windows.Forms.TextBox tbMatrixA_row;
		private System.Windows.Forms.Label lbMatrixA_row;
		private System.Windows.Forms.Label lbMatrixA_col;
		private System.Windows.Forms.TextBox tbMatrixA_col;
		private System.Windows.Forms.TextBox tbMatrixB_col;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox tbMatrixB_row;
		private System.Windows.Forms.Button btSetNumber;
		private System.Windows.Forms.Button btCalculation;
		private System.Windows.Forms.Label label4;
		

		public Form1()
		{

			m_startPoint.X = 16 ;
			m_startPoint.Y = 24 + 28 + 120 + 30  ;

			m_numRowMatricATextBox = 5 ;
			m_numColMatricATextBox = 7 ;

			m_numRowMatrixBTextBox = m_numColMatricATextBox ;
			m_numColMatrixBTextBox = 4 ;

			m_numRowMatriCTextBox = m_numRowMatricATextBox ;
			m_numColMatriCTextBox = m_numColMatrixBTextBox ;

			m_tbLength = 38 ;
			m_tbHeight = 20 ;

			int adistance = 50 ;
			// = length of A + a distance
			m_startPointMatrixB.X = m_startPoint.X + (m_numColMatricATextBox)*(m_tbLength+2) - 2 + adistance ;
			m_startPointMatrixB.Y = m_startPoint.Y ;


			int lbMatrixBlength = (m_numColMatrixBTextBox)*(m_tbLength+2) - 2; 
			m_FormLength = m_startPointMatrixB.X + lbMatrixBlength + adistance ;
			m_FormHeight = 500 ;

			arrTextBoxMatrixA = new TextBox[m_numRowMatricATextBox, m_numColMatricATextBox] ;
			db_MatrixA		  = new double [m_numRowMatricATextBox, m_numColMatricATextBox] ;

			arrTextBoxMatrixB = new TextBox[m_numRowMatrixBTextBox, m_numColMatrixBTextBox] ;
			db_MatrixB		  = new double [m_numRowMatrixBTextBox, m_numColMatrixBTextBox] ;

			arrTextBoxMatrixC = new TextBox[m_numRowMatriCTextBox, m_numColMatriCTextBox] ;
			db_MatrixC		  = new double [m_numRowMatriCTextBox, m_numColMatriCTextBox] ;

			SetProperty() ;

			// for initial functions of MATLAB DLL
			matrixcomputationslibInitialize();


		}

		///////// Using MATLAB Functions in DLL files
		[ DllImport( "matrixcomputationslib.dll ", CallingConvention = CallingConvention.Cdecl)] 
		public static extern void matrixcomputationslibInitialize(); 

		[ DllImport( "matrixcomputationslib.dll ", CallingConvention = CallingConvention.Cdecl)] 
		public static extern void matrixcomputationslibTerminate(); 

		[ DllImport( "matrixcomputationslib.dll ", CallingConvention = CallingConvention.Cdecl)] 
		public static extern void mlfMymtimes(int nargout, ref IntPtr y, IntPtr a, IntPtr b);


		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{

			// for termination functions of MATLAB DLL
			matrixcomputationslibTerminate();

			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.label1 = new System.Windows.Forms.Label();
			this.tbMatrixA_row = new System.Windows.Forms.TextBox();
			this.lbMatrixA_row = new System.Windows.Forms.Label();
			this.lbMatrixA_col = new System.Windows.Forms.Label();
			this.tbMatrixA_col = new System.Windows.Forms.TextBox();
			this.tbMatrixB_col = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.tbMatrixB_row = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.btSetNumber = new System.Windows.Forms.Button();
			this.btCalculation = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(40, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(112, 23);
			this.label1.TabIndex = 1;
			this.label1.Text = "Matrix A";
			this.label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
			// 
			// tbMatrixA_row
			// 
			this.tbMatrixA_row.Location = new System.Drawing.Point(24, 72);
			this.tbMatrixA_row.Name = "tbMatrixA_row";
			this.tbMatrixA_row.Size = new System.Drawing.Size(40, 20);
			this.tbMatrixA_row.TabIndex = 2;
			this.tbMatrixA_row.Text = "7";
			// 
			// lbMatrixA_row
			// 
			this.lbMatrixA_row.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lbMatrixA_row.Location = new System.Drawing.Point(4, 48);
			this.lbMatrixA_row.Name = "lbMatrixA_row";
			this.lbMatrixA_row.Size = new System.Drawing.Size(84, 16);
			this.lbMatrixA_row.TabIndex = 3;
			this.lbMatrixA_row.Text = "number of row";
			// 
			// lbMatrixA_col
			// 
			this.lbMatrixA_col.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lbMatrixA_col.Location = new System.Drawing.Point(104, 48);
			this.lbMatrixA_col.Name = "lbMatrixA_col";
			this.lbMatrixA_col.Size = new System.Drawing.Size(104, 16);
			this.lbMatrixA_col.TabIndex = 4;
			this.lbMatrixA_col.Text = "number of column";
			// 
			// tbMatrixA_col
			// 
			this.tbMatrixA_col.Location = new System.Drawing.Point(120, 72);
			this.tbMatrixA_col.Name = "tbMatrixA_col";
			this.tbMatrixA_col.Size = new System.Drawing.Size(48, 20);
			this.tbMatrixA_col.TabIndex = 5;
			this.tbMatrixA_col.Text = "5";
			this.tbMatrixA_col.TextChanged += new System.EventHandler(this.tbMatrixA_col_TextChanged);
			// 
			// tbMatrixB_col
			// 
			this.tbMatrixB_col.Location = new System.Drawing.Point(408, 72);
			this.tbMatrixB_col.Name = "tbMatrixB_col";
			this.tbMatrixB_col.Size = new System.Drawing.Size(48, 20);
			this.tbMatrixB_col.TabIndex = 10;
			this.tbMatrixB_col.Text = "5";
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label2.Location = new System.Drawing.Point(392, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(104, 16);
			this.label2.TabIndex = 9;
			this.label2.Text = "number of column";
			// 
			// label3
			// 
			this.label3.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label3.Location = new System.Drawing.Point(296, 48);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(84, 16);
			this.label3.TabIndex = 8;
			this.label3.Text = "number of row";
			// 
			// tbMatrixB_row
			// 
			this.tbMatrixB_row.Location = new System.Drawing.Point(312, 72);
			this.tbMatrixB_row.Name = "tbMatrixB_row";
			this.tbMatrixB_row.ReadOnly = true;
			this.tbMatrixB_row.Size = new System.Drawing.Size(40, 20);
			this.tbMatrixB_row.TabIndex = 7;
			this.tbMatrixB_row.Text = "";
			// 
			// label4
			// 
			this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label4.Location = new System.Drawing.Point(328, 16);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(112, 23);
			this.label4.TabIndex = 6;
			this.label4.Text = "Matrix B";
			this.label4.TextAlign = System.Drawing.ContentAlignment.TopCenter;
			// 
			// btSetNumber
			// 
			this.btSetNumber.Location = new System.Drawing.Point(200, 104);
			this.btSetNumber.Name = "btSetNumber";
			this.btSetNumber.Size = new System.Drawing.Size(80, 24);
			this.btSetNumber.TabIndex = 11;
			this.btSetNumber.Text = "Set Number";
			this.btSetNumber.Click += new System.EventHandler(this.btSetNumber_Click);
			// 
			// btCalculation
			// 
			this.btCalculation.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btCalculation.Location = new System.Drawing.Point(72, 328);
			this.btCalculation.Name = "btCalculation";
			this.btCalculation.Size = new System.Drawing.Size(88, 32);
			this.btCalculation.TabIndex = 12;
			this.btCalculation.Text = "Calculation";
			this.btCalculation.Click += new System.EventHandler(this.btCalculation_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(536, 397);
			this.Controls.Add(this.btCalculation);
			this.Controls.Add(this.btSetNumber);
			this.Controls.Add(this.tbMatrixB_col);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.tbMatrixB_row);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.tbMatrixA_col);
			this.Controls.Add(this.lbMatrixA_col);
			this.Controls.Add(this.lbMatrixA_row);
			this.Controls.Add(this.tbMatrixA_row);
			this.Controls.Add(this.label1);
			this.Name = "Form1";
			this.Text = "Multiple Matrixes";
			this.ResumeLayout(false);

		}
		#endregion

		public void SetTextBoxMatrixA() 
		{

			for(int i=0; i<m_numRowMatricATextBox; i++) 
			{
				for(int j=0; j<m_numColMatricATextBox; j++)  
				{
				 
					arrTextBoxMatrixA[i,j] = new System.Windows.Forms.TextBox();
					arrTextBoxMatrixA[i,j].Location = new System.Drawing.Point(m_startPoint.X + (m_tbLength+2)*j, m_startPoint.Y + (m_tbHeight+2)*i );
					arrTextBoxMatrixA[i,j].Name = "textBox1";
					arrTextBoxMatrixA[i,j].Size = new System.Drawing.Size(m_tbLength, m_tbHeight);
					arrTextBoxMatrixA[i,j].TabIndex = i;
					arrTextBoxMatrixA[i,j].Text = "0.0";
					this.Controls.Add(arrTextBoxMatrixA[i,j]) ;
				}
			}
		}


		public void SetLabelMatrixA() 
		{
			
			Label lbMatrixA = new System.Windows.Forms.Label();

			int lbMatrixAlength = (m_numColMatricATextBox)*(m_tbLength+2) - 2;
			lbMatrixA.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			lbMatrixA.Location = new System.Drawing.Point(m_startPoint.X, m_startPoint.Y - 40);
			lbMatrixA.Size = new System.Drawing.Size(lbMatrixAlength, 28);
			lbMatrixA.Name = "lbMatrixA";
			//lbMatrixA.TabIndex = 1;
			lbMatrixA.Text = "Matrix A";
			lbMatrixA.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

			this.Controls.Add(lbMatrixA) ;

		}

		public void SetLabelMatrixB() 
		{

⌨️ 快捷键说明

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