コード例 #1
0
        /// <summary>
        /// 这个方法讲已经选择的图形组成一个群组。
        /// </summary>
        public void doGroup()
        {
            //首先生成群组对象
            ShapeGroup group = new ShapeGroup(CurrentSelRect.arrlistShapeEle);

            CurrentSelRect.cancelAllSelect();//取消所有选择

            CurrentSelRect.addShapeEle(group);//再选择这个。

            //如下再在myshapes 中删除那些图形,并加上这一个。

            int intIndex=0;

            foreach (ShapeEle item in group.arrlistShapeEle)
            {
                intIndex = myShapes.IndexOf(item);
                myShapes.deleteShapeEle(item);

            }

            if (intIndex < 0)
                intIndex = 0;

            myShapes.addShapeEle(group, intIndex);

            //将这个作为已选择对象
            CurrentSelRect = new ShapeSelRect();
            CurrentSelRect.addShapeEle(group);
            Option = "select";

            saveOperatingRecord();
        }
コード例 #2
0
        /// <summary>
        /// 加载文件
        /// </summary>
        /// <param name="strFileName"></param>
        public string Loader(String strFileName)
        {
            try
            {
                using (Stream stream = new FileStream(strFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {

                    XmlSerializer   formatter = new XmlSerializer (typeof (Shapes));

                    myShapes = formatter.Deserialize(stream) as Shapes ;

                    myShapes.BarcodePageSettings.BarcodePaperLayout.Compute();

                    Zoom = myShapes.Zoom;//提取放大率,很重要。因为有时候保存的放大倍数不为1,则提取的时候是按照1的。

                    initOperatingRecord();

                    //并且要设置背景为已选择对象
                    //将纸张设为
                    ArrayList arrlist = new ArrayList();
                    arrlist.Add(myShapes.BarcodePageSettings.BarcodePaperLayout);
                    PropertyEventArgs background = new PropertyEventArgs(arrlist);
                    onObjectSelected(background);

                    _isNeedSave=false;// 刚开始是不需要保存的。
                }

            }
            catch (Exception exception)
            {
                //ClsErrorFile.WriteLine("加载不成功,原因是" , exception);
                //MessageBox.Show("加载不成功,原因是" + exception.Message);
                return "";
            }
            finally
            {

            }

            CurrentSelRect = new ShapeSelRect();// 重置选择框
            this.Refresh();

            return strFileName;
        }
コード例 #3
0
        /// <summary>
        /// 删除已经选择的形状
        /// </summary>
        public void deleteSelectShapeEle()
        {
            //迭代删除所有已经选择的
            foreach (ShapeEle item in CurrentSelRect.arrlistShapeEle)
            {
                myShapes.deleteShapeEle(item);

            }

            //删除后肯定是没有选择了,所以选择的要重置
            CurrentSelRect = new ShapeSelRect();

            saveOperatingRecord();

            this.Refresh();
        }
コード例 #4
0
        /// <summary>
        /// 撤销操作
        /// </summary>
        public void CtrlZ()
        {
            if (arrlistOperatingRecord.Count>0)
            {
                intOperatingItem--;//后退一位

                if (intOperatingItem < 0)
                    intOperatingItem = 0;//最低只能0
                myShapes = ((OperatingRecordItem)(arrlistOperatingRecord[intOperatingItem])).shapes;
                Zoom = Zoom;//设置放大率
                CurrentSelRect = ((OperatingRecordItem)(arrlistOperatingRecord[intOperatingItem])).shapeSellectRect;
                if (CurrentSelRect!=null)
                {
                    CurrentSelRect.SetSelRectXYWH();
                    onObjectSelected(new PropertyEventArgs(CurrentSelRect.arrlistShapeEle));
                }

                this.Refresh();
            }
        }
コード例 #5
0
        /// <summary>
        /// 粘贴操作
        /// </summary>
        public void CtrlV()
        {
            //粘贴操作是在剪贴和复制后的,首先判断_shapeEleRectCtrlXC是否为空
            try
            {

                //if (_shapeEleRectCtrlXC != null)
                {
                    //首先向右下角移动5毫米
                    _shapeEleRectCtrlXC.Redim("move", new PointF(0, 0), new PointF(5 * Zoom, 5 * Zoom));
                    _shapeEleRectCtrlXC.Zoom = Zoom;//设置放大率
                    _shapeEleRectCtrlXC.ReInit();

                    //从剪切板中取得图形
                    MemoryStream stream = Clipboard.GetAudioStream() as MemoryStream;
                    BinaryFormatter formatter = new BinaryFormatter();
                    CurrentSelRect = formatter.Deserialize(stream) as ShapeSelRect;
                    //首先向右下角移动5毫米
                    CurrentSelRect.Redim("move", new PointF(0, 0), new PointF(5 * Zoom, 5 * Zoom));
                    CurrentSelRect.Zoom = Zoom;//设置放大率
                    CurrentSelRect.ReInit();

                    //粘贴操作首先将这个对象深度拷贝到图形中
                    /**
                    try
                    {
                        using (MemoryStream memory2 = new MemoryStream())
                        {
                            XmlSerializer xs = new XmlSerializer(typeof(ShapeSelRect));

                            xs.Serialize(memory2, _shapeEleRectCtrlXC);//序列化
                            memory2.Seek(0, SeekOrigin.Begin);//移动到开头

                            //反序列化
                            XmlSerializer xs2 = new XmlSerializer(typeof(ShapeSelRect));
                            CurrentSelRect = xs2.Deserialize(memory2) as ShapeSelRect;//这样就深度拷贝到CurrentSelRect中了

                            memory2.Close();//销毁
                        }
                    }
                    catch (Exception ex)
                    {
                        //ClsErrorFile.WriteLine(ex);

                        if (ex.InnerException != null)
                            //ClsErrorFile.WriteLine(ex.InnerException.Message);
                    }

                     * */

                    //然后将这个添加到图形中
                    foreach (ShapeEle item in CurrentSelRect.arrlistShapeEle)
                    {
                        myShapes.addShapeEle(item);
                    }

                    //设置新粘贴出来的对象为已选择
                    PropertyEventArgs background = new PropertyEventArgs(CurrentSelRect.arrlistShapeEle);
                    onObjectSelected(background);
                    Option = "select";

                    switch (_strOptionCtrlXC)
                    {
                        case "CtrlX":
                            //如果是剪切操作,那么_shapeEleRectCtrlXC就没有了
                            _shapeEleRectCtrlXC = null;
                            //Clipboard.Clear();//清空
                            break;
                        case "CtrlC":
                            //如果是复制操作,就再一次执行复制操作,这样子每次都是往右下角移动的。
                            CtrlC();
                            break;

                        default:
                            break;
                    }

                    saveOperatingRecord();

                    //CurrentSelRect.Redim("move", new PointF(0, 0), new PointF(5 * Zoom, 5 * Zoom));

                    this.Refresh();//刷新
                }

            }
            catch (Exception ex2)
            {
                //ClsErrorFile.WriteLine(ex2);
                //throw;
            }
        }
コード例 #6
0
        /// <summary>
        /// 复制操作,复制操作只是将已选择对象序列化深度拷贝
        /// </summary>
        public void CtrlC()
        {
            _strOptionCtrlXC = "CtrlC";//设置状态为复制

            //CurrentSelRect对象的类是继承自shapeGroup,这个类是可以序列化的
            //如下是用内存流来序列化
            try
            {
                using (MemoryStream memory1 = new MemoryStream())
                {
                    XmlSerializer xs = new XmlSerializer(typeof(ShapeSelRect));

                    xs.Serialize(memory1, CurrentSelRect);//序列化
                    memory1.Seek(0, SeekOrigin.Begin);//移动到开头

                    //反序列化
                    XmlSerializer xs2 = new XmlSerializer(typeof(ShapeSelRect));
                    _shapeEleRectCtrlXC = xs2.Deserialize(memory1) as ShapeSelRect;//这样就深度拷贝到_shapeEleRectCtrlXC中了

                    //Clipboard.SetDataObject(_shapeEleRectCtrlXC);//复制到剪切板中

                    memory1.Close();//销毁

                    //添加自定义对象到剪切板
                    MemoryStream stream = new MemoryStream();
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(stream, _shapeEleRectCtrlXC);
                    Clipboard.SetData(DataFormats.Serializable, stream);
                    Clipboard.SetAudio(stream);

                    //保存记录
                    saveOperatingRecord();
                }
            }
            catch (Exception ex)
            {
                //ClsErrorFile.WriteLine(ex);

                if (ex.InnerException != null)
                    ClsErrorFile.WriteLine(ex.InnerException.Message);
            }
        }
コード例 #7
0
 /// <summary>
 /// 全选操作
 /// </summary>
 public void CtrlA()
 {
     if (myShapes.arrlistShapeEle.Count>0)
     {
          CurrentSelRect = new ShapeSelRect(myShapes.arrlistShapeEle);
     }
 }