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

📄 bnode1.cs

📁 基于BP算法的贝叶斯网络参数学习
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace bs
{
	/// <summary>
	/// BNode1 的摘要说明。
	/// </summary>
	public class BNode1 : System.Windows.Forms.TextBox
	{
		/// <summary> 
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private Point m_Location;
		private int nodeWidth;
		private int x,y,x1,y1; 
		private bool BeginDrag = false;
		private Point m_from;//=new Point(this.Left+this.Width/2,this.Top+this.Height);
		private Point m_to;//=new Point(this.Left+this.Width/2,this.Top);
		//private bool drawLine = false;
		public bool  draged=false;
		//private string m_text;
		private bool m_LocationChanged=false;
		//private int width,height;
		//private float m_fontSize=12F;
		//m_fontSize=12F;
		
		public ArrayList Parents;
		public double[,] CPT;
		public int Evidence=-1;

		private string m_name;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem3;
        private int m_id;
		private int m_range=2;
		public int indegree=0;
		public int outdegree=0;
		public int degree=0;
	    public ArrayList state=new ArrayList();
        public string m_style = "";
        public double just = 1.0;
		
		 //public string[] state=new string[];
	
		
		//private int nodeHeight;
		//private readonly Doc HostForm;

///
///*** construter
		public BNode1(Point m_Location):base()
		{
			InitializeComponent();
			this.Location=m_Location;
			state.Add("Yes");
			state.Add("No");
			Parents=new ArrayList();
			//state.Add("fdf");
			//host=HostForm;
			//MakeItEllipse();
			//nodeWidth=120;
			//height=30;
			//m_fontSize=12F;

        }
        #region 注释
        //public BNode1(BNode1 node)
		//{
		//	InitializeComponent();
		//	this.Location=node.m_Location;
		//}

		//public BNode1(string nodename)
		//{
			//BNode1 node
		//}
		
	
	///	***Properties
	///	
	///	
	///	
        /*public double[,] cpt
        {CPT=new double[100,100];
            get
        {
            return CPT;
        }
            set
            {
                for(int i=0;i<CPT.Length;i++)
					
                CPT[][]=value;
                */
        #endregion
        public int evidence
		{
			get
			{
				//Evidence=-1;
				return Evidence;
			}
			set
			{
				Evidence=value;
			}
		}
		public ArrayList State
		{
			get
			{
				//state.Add("Yes");
				//state.Add("No");
				return state;
			}
			set
			{
				for(int i=0;i<state.Count;i++)
				{
					state.Add(value);
				}
			}
		}
			
		public string name
		{
			get
			{
				m_name=this.Text;
				return m_name; }
			set
			{
				m_name=value;
			}
		
		}
		public int InDegree
		{
			get
			{
				return indegree;
			}
			set
			{
				indegree=value;
			}
		}

		public int OutDegree
		{
			get
			{
				return outdegree;
			}
			set
			{
				outdegree=value;
			}
		}
		public int Degree
		{
			get
			{
				degree=indegree+outdegree;
				return degree;
			}
			set
			{
				degree=value;
			}
		}
		//public int ID
		//{
		//	get{ return m_id; }
		//}
		public int ID
		{
			get{ return m_id; }
			set
			{
				m_id=value;
			}
		}

		public int Range
		{
			get
            {
                return m_range; 
            }
			set
			{
				m_range=value;
			}
		
		}
        public string style;
        //{
        //    get
        //    {

        //        return this.style;
        //    }
        //    set
        //    {
        //        style = value;
        //    }
        //}	

		public Point nodeLocation
		{
			get
			{
				return ClientRectangle.Location;
			}
			set
			{
				m_Location=value;
			}
		}

		public int NodeWidth
		{
			get
			{
				nodeWidth=this.Size.Width;
				return nodeWidth;
			}
			set
			{
				nodeWidth=value;
			}


		}

		public Point from
		{
			get
			{
				m_from= new Point(this.Left+this.Width/2,this.Top+this.Height);
				return m_from;
			}
			set
			{
				m_from=value;
			}
			
		}
		public Point to
		{
			get
			{
				m_to=new Point(this.Left+this.Width/2,this.Top);
				return m_to;
			}
			set
			{
				m_to=value;
			}
		}

		/// <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()
		{
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			// 
			// menuItem1
			// 
			this.menuItem1.Index = -1;
			this.menuItem1.Text = "&New Node";
			// 
			// menuItem2
			// 
			this.menuItem2.Index = -1;
			this.menuItem2.Text = "&New Node";
			// 
			// menuItem3
			// 
			this.menuItem3.Index = -1;
			this.menuItem3.Text = "&New Node";
			// 
			// BNode1
			// 
			this.AllowDrop = true;
			this.BackColor = System.Drawing.Color.Linen;
			this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.Cursor = System.Windows.Forms.Cursors.Arrow;
			this.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.ForeColor = System.Drawing.Color.Black;
			this.HideSelection = false;
			this.ImeMode = System.Windows.Forms.ImeMode.Off;
			this.Multiline = true;
			this.Text = "Node";
			this.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.BNode1_KeyDown);
			this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.BNode1_MouseDown);
			this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.BNode1_KeyPress);
			this.LocationChanged += new System.EventHandler(this.BNode1_LocationChanged);
			this.MouseEnter += new System.EventHandler(this.BNode1_MouseEnter);
			this.DoubleClick += new System.EventHandler(this.BNode1_DoubleClick);
			this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.BNode1_MouseUp);
			this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.BNode1_MouseMove);
			this.MouseLeave += new System.EventHandler(this.BNode1_MouseLeave);
			this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.BNode1_KeyUp);

		}
		#endregion

	//****events
		public void clear()
		{
			Evidence = -1;
		}

		public void MakeItEllipse(int width,int height)

		{  // m_fontSize=fontSize;
			//this.BackColor = System.Drawing.Color.Teal;
			this.BorderStyle=BorderStyle.None;
			this.TextAlign=HorizontalAlignment.Center;
			GraphicsPath gp=new GraphicsPath();
			//gp.AddEllipse(new Rectangle(ClientRectangle.Left,ClientRectangle.Top,this.Size.Width,this.Size.Height));
			gp.AddEllipse(new Rectangle(ClientRectangle.Left,ClientRectangle.Top,width,height));
			this.Region=new Region(gp);
			
		}

		public bool IsInNode(Point e)
		{
			//if(this.Left<e.X<(this.Left+this.Width)&&this.Top<e.Y<(this.Top+this.Height))
			if(e.X>this.Left-5&&e.X<(this.Left+this.Width+5)&&e.Y>this.Top-5&&e.Y<(this.Top+this.Height+5))
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		private void BNode1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{	
			if( e.KeyChar == (char)13)
            {
			    //MakeItEllipse(this.Width,this.Height);
			    this.ReadOnly=true;
				this.HideSelection=true;
				//this.Enabled=false;
				//this.CanFocus=false;
				//this.Cursor=Cursors.No;
				//this.Visible=false;
				//this.CanFocus=false;
				//MessageBox.Show("(char)13");
		      }
		//	if(e.KeyChar==(char)65)
			//{
			//		this.Cursor=Cursors.Cross;
			//	drawLine=true;
			//}
			//if(e.KeyChar==(char)61)
				//this.Cursor==Cursors.Cross;
		
		}

		private void BNode1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{ //this.BackColor=Color.DarkSeaGreen;
			if(this.Cursor==Cursors.Arrow)
			{
				x = e.X; 
				y = e.Y; 
				BeginDrag = true; 
            }
			if(this.Focus())
			{
				Pen p = new Pen(Color.Black,1);//你在定义pen的时候可以设置它的虚线宽度
				//p.DashStyle=DashStyle.Dot;
				Graphics g=this.CreateGraphics();
				g.DrawRectangle(p,this.Left-5,this.Top-5,this.Width+10,this.Height+10);
				//this.Capture=true;
				//MessageBox.Show("dfd");
				//this.Focus();
			}
		//GraphicsPath gp=new GraphicsPath();
			//gp.AddEllipse(new Rectangle(ClientRectangle.Left,ClientRectangle.Top,this.Size.Width,this.Size.Height));
		//gp.AddRectangle(new Rectangle(ClientRectangle.Left,ClientRectangle.Top,this.Width,this.Height));
		//	if(this.Cursor==Cursors.Cross)
			//{
			//	drawLine=true;
		///	from=new Point(this.Left+this.Width/2,this.Top+this.Height);
			//MessageBox.Show(from.X.ToString());
			//}
		//Pen p = new Pen(Color.Black,1);//你在定义pen的时候可以设置它的虚线宽度
			///p.DashStyle=DashStyle.Dot;
			//Graphics g=this.CreateGraphics();
			//g.DrawRectangle(p,this.Left-5,this.Top-5,this.Width+10,this.Height+10);
		//	p.DashPattern =//划虚线
				//g.drawlin(p,x1,y1,x2,y2);
		}

		private void BNode1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if(BeginDrag)
			{ 
				this.Left += e.X - x; 
				this.Top += e.Y - y; 
				this.from=new Point(this.Left+this.Width/2,this.Top+this.Height);
				this.to=new Point(this.Left+this.Width/2,this.Top);
				BeginDrag = false; 
				draged=true;
			} 
			m_LocationChanged=false;
		//	if(this.Cursor==Cursors.Cross&&drawLine)
			///{
				//drawLine=false;
			//	to=new Point(this.Left+this.Width/2,this.Top+this.Height);
				//MessageBox.Show(from.X.ToString());
				//this.Cursor=Cursors.Arrow;
		//	}

		}

		private void BNode1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if(BeginDrag)
			{ 
				x1 = this.Left + e.X - x; 
				y1 = this.Top + e.Y - y; 
				Invalidate(); 
			} 
			//if(e.Button==MouseButtons.Right)
			///{
			///		Pen p = new Pen(Color.Black,1);//你在定义pen的时候可以设置它的虚线宽度
			//	p.DashStyle=DashStyle.Dot;
			//	Graphics g=this.CreateGraphics();
			//	g.DrawRectangle(p,this.Left-5,this.Top-5,this.Width+10,this.Height+10);
			//}
		}

		

		private void BNode1_MouseEnter(object sender, System.EventArgs e)
		{//if(
			//this.BackColor=Color.DarkSeaGreen;
			
		}
	//	public  void OnMouseEnter(object sender,System.Windows.Forms.MouseEventArgs e)
		//{
			//base.MouseEnter();
		//	if(e.Button==MouseButtons.Left)
		//		this.BackColor=Color.DarkSeaGreen;
		//}

		private void BNode1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.A)
				this.Cursor=Cursors.Cross;
		}

		private void BNode1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
		if(e.KeyCode==Keys.A)
			this.Cursor=Cursors.No;
		}

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

		//public override void OnClick(object sender,System.EventArgs e)
		//{
		//	base.Click();
		//	Pen p = new Pen(Color.Black,1);//你在定义pen的时候可以设置它的虚线宽度
		//	p.DashStyle=DashStyle.Dot;
		
		//	Graphics g=this.CreateGraphics();
			//g.DrawRectangle(p,this.Left-5,this.Top-5,this.Width+10,this.Height+10);
		//}
		//public override void RightButtonDown(object sender,System.EventArgs e)
		////{
			//base.

		private void BNode1_LocationChanged(object sender, System.EventArgs e)
		{
			//this.Container
			m_LocationChanged=true;
		}

		public bool locationChanged()
		{
			if(m_LocationChanged)
				return true;
			else
				return false;
		}

		private void BNode1_MouseLeave(object sender, System.EventArgs e)
		{
		//this.BackColor = System.Drawing.Color.Teal;
		}

		
			
	}
}

⌨️ 快捷键说明

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