Example #1
0
        /// <summary>
        /// “确定”按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void certainButton_Click(object sender, EventArgs e)
        {
            string str = "[";

            foreach (Control control in this.Controls)
            {
                if (control is PanelExLine)
                {
                    PanelExLine pe = (PanelExLine)control;
                    if (pe.panelEx == null)
                    {
                        MessageBox.Show("请完成所有连线");
                        return;
                    }
                    else
                    {
                        str += pe.index + "(" + pe.panelEx.index + "),";
                    }
                }
            }
            str  = str.Substring(0, str.Length - 1);
            str += "]";
            AnswerEvent?.Invoke(str);
            Close();
            //System.Diagnostics.Debug.WriteLine(str);
        }
Example #2
0
        //线段开始处坐标
        private Point getLineStartPoint(Point p, PanelExLine tempP)
        {
            float bTriangleX = p.X + tempP.Size.Width / 2.0F - tempP.center.X;
            float bTriangleY = p.Y + tempP.Size.Height / 2.0F - tempP.center.Y;
            float length     = (float)Math.Sqrt(Math.Pow(bTriangleX, 2) + Math.Pow(bTriangleY, 2));
            float sTriangleX = bTriangleX / length * (tempP.Size.Width / 2.0F);
            float sTriangleY = bTriangleY / length * (tempP.Size.Height / 2.0F);

            return(new Point((int)(tempP.center.X + sTriangleX), (int)(tempP.center.Y + sTriangleY)));
        }
Example #3
0
        public void addTextAndPanel()
        {
            for (int i = 1; i <= _lineQuestion.answerCount; i++)
            {
                Label leftTxt = new Label();
                leftTxt.Name     = "leftTxt" + (char)(i + 64);
                leftTxt.Text     = _lineQuestion.leftAnswerList[i - 1].leftAnswer;
                leftTxt.Location = new Point(30, 40 + (i - 1) * 80);
                leftTxt.AutoSize = true;
                this.Controls.Add(leftTxt);

                PanelExLine panelExLine = new PanelExLine("panel" + (char)(i + 64), new Point(80, 35 + (i - 1) * 80), new Size(25, 25));
                panelExLine.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel_MouseDown);
                panelExLine.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel_MouseMove);
                panelExLine.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.panel_MouseUp);
                this.Controls.Add(panelExLine);

                Label rightTxt = new Label();
                rightTxt.Name     = "rightLabel" + i;
                rightTxt.Text     = _lineQuestion.rightAnswerList[i - 1].rightAnswer;
                rightTxt.Location = new Point(300, 40 + (i - 1) * 80);
                rightTxt.AutoSize = true;
                this.Controls.Add(rightTxt);

                PanelEx panelEx = new PanelEx("panel" + i, new Point(265, 35 + (i - 1) * 80), new Size(25, 25));
                this.Controls.Add(panelEx);

                //遍历所有的PanelEx,存入集合中
                foreach (Control control in this.Controls)
                {
                    if (control is PanelEx)
                    {
                        PanelEx pe = (PanelEx)control;
                        panelExList.Add(pe);
                    }
                }
                //遍历所有的PanelExLine,存入集合中
                foreach (Control control in this.Controls)
                {
                    if (control is PanelExLine)
                    {
                        PanelExLine pe = (PanelExLine)control;
                        panelExLineList.Add(pe);
                    }
                }
            }
        }
Example #4
0
 private void panel_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         panel = (PanelExLine)sender;
         if (panel.panelEx != null)
         {
             if (panel.panelEx.panelExLine != null)
             {
                 panel.panelEx.panelExLine = null;
             }
             panel.panelEx = null;
         }
         //鼠标点击时相对于控件的位置进行记录
         mouseDownPoint = new Point(MousePosition.X - this.Location.X, MousePosition.Y - this.Location.Y);
     }
 }