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

📄 probcontrol.cs

📁 用C#开发的录井油气识别专家系统
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using mathfunsharp;
using System.Diagnostics;


namespace expert
{
	/// <summary>
	/// ProbControl 的摘要说明。
	/// </summary>
	public class ProbControl : System.Windows.Forms.UserControl
	{
		/// <summary> 
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private float vexpt;
		private float vsigma;
		private string vparam;
		private string vresult;
		private float vmin;
		private float vmax;
		private int vcount;
		private int vmonotype;

		private float range1;
		private float range0;
			
			
		private PointF[] points;

		public ProbControl()
		{
			// 该调用是 Windows.Forms 窗体设计器所必需的。
			InitializeComponent();
			vexpt=0;
			vsigma=12.0100f;
			vparam="未名参数";
			vresult="试油结果";
			vmax=-10f;
			vmin=10f;
			vcount=100;

			range1=10*Math.Max(Math.Abs(vmax-vexpt),Math.Abs(vmin-vexpt))+vexpt;
			range0=vexpt*2.0f-range1;
		

			// TODO: 在 InitializeComponent 调用后添加任何初始化

		}

		/// <summary> 
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// 设计器支持所需的方法 - 不要使用代码编辑器 
		/// 修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			// 
			// ProbControl
			// 
			this.Name = "ProbControl";
			this.Size = new System.Drawing.Size(464, 296);
			this.Load += new System.EventHandler(this.ProbControl_Load);

		}
		#endregion

		private void ProbControl_Load(object sender, System.EventArgs e)
		{
		
		}

		protected void DrawAxis(System.Windows.Forms.PaintEventArgs e)
		{
			PointF[] p=new PointF[]{new PointF(5f,-5f),new PointF(vexpt,0)};
			PointF[] p1=new PointF[]{new PointF(vexpt,0.0f),
										new PointF(vmin,0.0f),
										new PointF(vmax,0.0f),
										new PointF(vexpt,0.1f),
										new PointF(vexpt,0.2f),
										new PointF(vexpt,0.3f),
										new PointF(vexpt,0.4f),
										new PointF(vexpt,0.5f),
										new PointF(vexpt,0.6f),
										new PointF(vexpt,0.7f),
										new PointF(vexpt,0.8f),
										new PointF(vexpt,0.9f),
										new PointF(vexpt,0.10f),
										new PointF(vmin,0.0f),
										new PointF(vmax,0.0f)
				
									};
			Matrix mx=e.Graphics.Transform;
			mx.TransformPoints(p1);

			
			mx.Invert();
			mx.TransformVectors(p);
			Pen pen=new Pen(Color.Red,0);
			Trace.Assert(pen!=null);
			
			float pace;
			float x;
			float y;


			e.Graphics.DrawLine(pen,vexpt,0,vexpt,1);
			pace=0.1f;
			

			
			
			try
			{
				GraphicsState transState = e.Graphics.Save();
				e.Graphics.ResetTransform();

				Font drawFont = new Font("Arial",10f);//p[0].Y);
				SolidBrush drawBrush = new SolidBrush(Color.Black);
				StringFormat drawFormat = new StringFormat();
				drawFormat.Alignment=StringAlignment.Center;
				e.Graphics.TextRenderingHint=System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
				
				e.Graphics.DrawString(vexpt.ToString(),drawFont,drawBrush,p1[0],drawFormat);


				
				float tempf;
				drawFormat.Alignment=StringAlignment.Far;
				for(int i=3;i<=11;i++)
				{
					tempf=0.1f*(i-2f);
					e.Graphics.DrawString(tempf.ToString(),drawFont,drawBrush,p1[i],drawFormat);
				}


				e.Graphics.Restore(transState);

			}
			catch(Exception ec)
			{
				MessageBox.Show(ec.Message);
			}

				
			for(y=0f;y<=1.0f;y+=pace)
			{
				e.Graphics.DrawLine(pen,vexpt,y,vexpt+p[0].X,y);
				//e.Graphics.DrawString(y.ToString(), drawFont, drawBrush, vexpt,y);
			
			}


			e.Graphics.DrawLine(pen,range0,0,range1,0);
			pace=(range1-range0)/20f;
			for(x=range0;x<=range1;x+=pace)
			{
				e.Graphics.DrawLine(pen,x,0,x,p[0].Y);
			}

			pen=new Pen(Color.Green,0);
			CMathFunc a=new CMathFunc();
			x=vmin;
			y=(float)a.CNormal(vexpt,vsigma,x,vmonotype);
			e.Graphics.DrawLine(pen,x,0,x,y);
			
			x=vmax;
			y=(float)a.CNormal(vexpt,vsigma,x,vmonotype);
			e.Graphics.DrawLine(pen,x,0,x,y);	
		}
		
		protected override  void OnPaint(System.Windows.Forms.PaintEventArgs e)
		{
			if(this.InvalidDatatoDraw)
				return;
			float f=range1-range0;
			Trace.Assert(f>0f);

			Matrix myMatrix;
			Rectangle rect=e.ClipRectangle;
			Pen blackPen=new Pen(Color.Black,0);
			myMatrix=new Matrix();
			try
			{

				myMatrix.Translate(rect.Width/2,rect.Height, MatrixOrder.Prepend);
				myMatrix.Multiply(new Matrix(1,0,0,-1,0,0),MatrixOrder.Prepend);
				myMatrix.Translate(0,20, MatrixOrder.Prepend);
				myMatrix.Scale(rect.Width/f,rect.Height-20, MatrixOrder.Prepend);
				myMatrix.Translate(-vexpt,0, MatrixOrder.Prepend);
			}

			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);

			}

			 
			 
			Font drawFont = new Font("Arial", 10);
			SolidBrush drawBrush = new SolidBrush(Color.Black);
			StringFormat drawFormat = new StringFormat();
			drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
			e.Graphics.DrawString(vparam +"--"+ vresult , drawFont, drawBrush, 10, 10);//, drawFormat);

			Trace.Assert(myMatrix!=null);

			try
			{
				e.Graphics.Transform=myMatrix;
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);

			}

			
			
			 
			if(points==null || points.Length<=1)
				return;

			
			
			DrawAxis(e);
			e.Graphics.DrawLines(blackPen,points);

			
			

			

			



		
		}
		private void CalcuPoints()
		{
			CMathFunc a=new CMathFunc();
			
			float pace;
			pace=(range1-range0)/100;
			points=new PointF[101];
			double f;
			int i=0;
			float x=range0;
			for(i=0;i<=100;i++)
			{
				f=a.CNormal(vexpt,vsigma,x,this.vmonotype);
				


				points[i].X=(float)x;
				points[i].Y=(float)f;
				x+=pace;
				
			}
		}
		
		protected override  void OnSizeChanged(System.EventArgs e)
		{
			Invalidate();
		
		}

		/// <summary>
		/// 设置数学期望和方差
		/// </summary>
		public void SetExptSigma(DataRowView dr)
		{
			try
			{
				vcount=(int)(dr["样本数"]);
				vparam=(string)(dr["参数"]);
				vresult=(string)(dr["试油结果"]);
				vmax=(float)(dr["最大值"]);
				vmin=(float)(dr["最小值"]);
				vexpt=(float)(dr["均值"]);
				vsigma=(float)(dr["偏差"]);
			
				vmonotype=(int)(dr["单调"]);
			}
			catch(InvalidCastException)
			{
				InvalidDatatoDraw=true;
				return;

			}
			
			
			InvalidDatatoDraw=false;


			range1=2*Math.Max(Math.Abs(vmax-vexpt),Math.Abs(vmin-vexpt))+vexpt;
			range0=vexpt*2.0f-range1;
			if(range0==range1)
			{
				range1=1f ;
				range0=-1f;
			}

			CalcuPoints();
			Invalidate();
			Refresh();
		}
		public delegate void SetEXPSGMDelegate(DataRowView dr);

		/// <summary>
		/// 标示数据是否有效,无效的数据无法图示
		/// </summary>
		private bool InvalidDatatoDraw;


	}
}

⌨️ 快捷键说明

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