コード例 #1
0
        /// <summary>
        /// 載入form事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            number_label.Visible = false;                                 //一開始 查找用label不會顯示

            blackpen       = new Pen(Color.Black);                        //用黑線畫dxf ***可被取代
            blackpen.Width = 1;
            draw_dxf       = new Bitmap(dxf_view.Width, dxf_view.Height); //先在bitmap畫
            using (dxfpen = Graphics.FromImage(draw_dxf))
            {
                dxfpen.Clear(Color.White); //底色 白
            }
            dxf_view.Image = draw_dxf;     //刷新

            count         = 0;             //標點資料列建立
            pointarray    = new pointer[10];
            pointarray[0] = new pointer();

            s       = new Point(0, 0);//起始看bitmap的位置(0,0)
            sizenum = 1;

            dxflines   = new List <line>();//dxf的list建立
            dxfcircles = new List <circle>();
            dxftext    = new List <text>();

            icon1 = Image.FromFile("dot1.png"); //黑色準心 沒用到
            icon2 = Image.FromFile("dot2.png"); //紅色準心 點滑鼠的圖
            rock  = Image.FromFile("rock.png"); //拖拉時的手
        }
コード例 #2
0
 /// <summary>
 /// 跟原點距離
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 private int pointer_x_to_zero(pointer p)
 {
     return(p.location.X - zeropoint.drawpoint.X);
 }
コード例 #3
0
        /// <summary>
        /// 圖面點擊事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dxf_view_MouseClick(object sender, MouseEventArgs e)
        {
            DataGridViewRowCollection pdata = pointdata.Rows;                                                        //宣告右邊表格"行"控制項

            if (e.Button == MouseButtons.Right && !active_zeropoint && zero_exist && ruler_exist && !mouse_move_pic) //普通標點 條件:滑鼠右鍵,沒在標原點,原點存在,比例尺存在
            {
                count++;                                                                                             //計算標到第幾點
                pointarray[count] = new pointer(s.X + e.X, s.Y + e.Y, count);                                        //用dxf_view座標與滑鼠座標算出該像素在bitmap位置
                draw_dxf.SetPixel(s.X + e.X, s.Y + e.Y, Color.Red);                                                  //標的位置//如點到bitmap外會崩潰 FIX ME
                pointarray[count].x_to_zero = pointer_x_to_zero(pointarray[count]);                                  //與原點距離 單位:像素
                pointarray[count].y_to_zero = pointer_y_to_zero(pointarray[count]);

                if (mouselock)
                {
                    pointarray[count].ori_x = ori_lock_x;//存鎖點的資料
                    pointarray[count].ori_y = ori_lock_y;
                    if (zeropoint.ori_x >= 0 && zeropoint.ori_y >= 0)
                    {
                        pointarray[count].x_to_zero_dou = (pointarray[count].ori_x - zeropoint.ori_x) * pixellength;//有原始資料便用原始資料算距離
                        pointarray[count].y_to_zero_dou = (pointarray[count].ori_y - zeropoint.ori_y) * pixellength;
                    }
                    else
                    {
                        pointarray[count].x_to_zero_dou = pointarray[count].x_to_zero * pixellength;//用比例尺算與原點距離
                        pointarray[count].y_to_zero_dou = pointarray[count].y_to_zero * pixellength;
                    }
                }
                else
                {
                    pointarray[count].ori_x         = -1;                                        //沒鎖點便存-1
                    pointarray[count].ori_y         = -1;
                    pointarray[count].x_to_zero_dou = pointarray[count].x_to_zero * pixellength; //用比例尺算與原點距離
                    pointarray[count].y_to_zero_dou = pointarray[count].y_to_zero * pixellength;
                }

                pointarray[count].sizenum = sizenum;//標點時的縮放倍率
                dxf_view.Image            = cut(s, dxf_view.Width, dxf_view.Height);

                pdata.Add(new object[] { pointarray[count].number.ToString(), pointarray[count].x_to_zero_dou.ToString(), pointarray[count].y_to_zero_dou.ToString() });     //資料顯示在右邊表格

                label1.Text = label1.Text + "\n" + pointarray[count].x_to_zero_dou.ToString() + "\n" + pointarray[count].y_to_zero_dou.ToString() + "\n" + count.ToString(); //測試用 ***完成後應刪除
            }

            else if (active_zeropoint && ruler_exist && e.Button == MouseButtons.Right && !mouse_move_pic) //原點標點
            {
                if (zero_exist)                                                                            //如有上個原點 將其變回白色
                {
                    draw_dxf.SetPixel(zeropoint.drawpoint.X, zeropoint.drawpoint.Y, Color.White);
                }
                zeropoint = new originpoint(new Point(s.X + e.X, s.Y + e.Y));//用dxf_view座標和滑鼠座標算在bitmap位置
                draw_dxf.SetPixel(s.X + e.X, s.Y + e.Y, Color.Blue);
                dxf_view.Image = cut(s, dxf_view.Width, dxf_view.Height);
                if (mouselock)
                {
                    zeropoint.ori_x = ori_lock_x;//存鎖點的資料
                    zeropoint.ori_y = ori_lock_y;
                }
                else
                {
                    zeropoint.ori_x = -1;//沒鎖點便存-1
                    zeropoint.ori_y = -1;
                }
                active_zeropoint = false;
                zero_exist       = true;
                label1.Text      = label1.Text + "\n" + zeropoint.drawpoint.X.ToString() + "\n" + zeropoint.drawpoint.Y.ToString();//測試用 ***完成後應刪除
            }

            if (startrulerset && e.Button == MouseButtons.Right && !mouse_move_pic)//設比例尺 點圖面上兩點手動填入距離算比例尺
            {
                if (c == 1)
                {
                    rulers = new Point(s.X + e.X, s.Y + e.Y);        //第一點座標
                }
                if (c == 2)
                {
                    rulere = new Point(s.X + e.X, s.Y + e.Y);        //第二點座標
                }
                c++;
                if (c >= 3 && length_refer.Text != "" && length_refer.Text != "在此輸入長度")//三以上且有輸入距離會計算比例尺
                {
                    length_refer.Visible = false;
                    startrulerset        = false;
                    ruler_exist          = true;
                    rulersetter();//計算方法
                }
            }
        }
コード例 #4
0
 private int pointer_y_to_zero(pointer p)
 {
     return(p.location.Y - zeropoint.drawpoint.Y);
 }