示例#1
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //MessageBoxError("hi", "bye");
            MessageBoxButtons buttons = MessageBoxButtons.YesNoCancel;
            DialogResult      result;

            result = MessageBox.Show("Do you want to save picture before exit?", "Exit...", buttons);
            if (result == DialogResult.Yes)
            {
                sfdlgSave.InitialDirectory = Application.StartupPath.ToString() + "\\" + SaveLoadPath;
                if (sfdlgSave.ShowDialog() != DialogResult.Cancel)
                {
                    if (sfdlgSave.FileName != "")
                    {
                        FileStream fs = (FileStream)sfdlgSave.OpenFile();
                        userfigsbinser = new MyCustomFiguresBinarySerializer();
                        userfigsbinser.SaveFiguresList(fs, FigList);
                        fs.Close();
                    }
                }
            }
            else if (result == DialogResult.Cancel)
            {
                e.Cancel = true;
            }
            else if (result == DialogResult.No)
            {
                e.Cancel = false;
            }
        }
示例#2
0
        private void ConnectUserFigures()
        {
            try
            {
                foreach (var figpath in UserFigsList)
                {
                    var fs = new FileStream(figpath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    userfigsbinser = new MyCustomFiguresBinarySerializer();
                    var tmplist = userfigsbinser.LoadFiguresList(fs, TypesList, UserNamesList, SourceLists);
                    fs.Close();
                    SourceLists.Add(tmplist);
                    int length = (Application.StartupPath.ToString() + "\\" + UserFiguresPath).Length;

                    var nextRB = new RadioButton();
                    nextRB.Parent = grboxFigures;
                    nextRB.Left   = 8;
                    nextRB.Top    = StartRBPos;
                    StartRBPos   += 27;
                    nextRB.Width  = 100;
                    nextRB.Height = 21;
                    string tmpstr = figpath.Substring(length + 1);
                    var    name   = tmpstr.Remove(tmpstr.Length - 4);
                    nextRB.Text = name;
                    UserNamesList.Add(name);

                    nextRB.CheckedChanged += (a, b) => {
                        try
                        {
                            CurrentList = tmplist;
                            CurrentName = name;
                            FigParams   = new Object[] { CurrentName, CurrentList, CurrPen, 0, 0, 0, 0 };
                            figure      = (Figure.Figure)Activator.CreateInstance(Type.GetType("Lab1.UserFigure"), FigParams);
                            isChanged   = true;
                            isPointer   = false;
                        }
                        catch (Exception ee)
                        {
                            MessageBoxException(ee.Message);
                        }
                    };
                }
            }
            catch (Exception e)
            {
                MessageBoxException(e.Message);
            }
        }
示例#3
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     isOpenFile                 = true;
     sfdlgSave.DefaultExt       = SavedPicturesExtension;
     sfdlgSave.Filter           = "MonsterPaint Pictures|*." + SavedPicturesExtension + "|All Files|*.**";
     sfdlgSave.InitialDirectory = Application.StartupPath.ToString() + "\\" + SaveLoadPath;
     if (sfdlgSave.ShowDialog() != DialogResult.Cancel)
     {
         if (sfdlgSave.FileName != "")
         {
             FileStream fs = (FileStream)sfdlgSave.OpenFile();
             userfigsbinser = new MyCustomFiguresBinarySerializer();
             userfigsbinser.SaveFiguresList(fs, FigList);
             fs.Close();
         }
     }
     rbPointer.Checked = true;
 }
示例#4
0
 private void btnLoad_Click(object sender, EventArgs e)
 {
     isOpenFile                 = true;
     ofdlgLoad.Filter           = "MonsterPaint Pictures|*." + SavedPicturesExtension + "|All Files|*.**";
     ofdlgLoad.InitialDirectory = Application.StartupPath.ToString() + "\\" + SaveLoadPath;
     if (ofdlgLoad.ShowDialog() != DialogResult.Cancel)
     {
         if (ofdlgLoad.FileName != "")
         {
             FileStream fs = (FileStream)ofdlgLoad.OpenFile();
             userfigsbinser = new MyCustomFiguresBinarySerializer();
             FigList.Clear();
             lboxFigures.Items.Clear();
             grRez.Clear(Color.Transparent);
             grMajor.Clear(Color.Transparent);
             pictureBox1.Refresh();
             CurrFig   = -1;
             isPressed = false;
             isMoved   = false;
             isChanged = false;
             try
             {
                 FigList = userfigsbinser.LoadFiguresList(fs, TypesList, UserNamesList, SourceLists);
                 fs.Close();
             }
             catch (System.Runtime.Serialization.SerializationException ee)
             {
                 MessageBoxButtons buttons = MessageBoxButtons.OK;
                 DialogResult      result;
                 result            = MessageBox.Show(ee.Message, "Loading error.", buttons);
                 rbPointer.Checked = true;
             }
             FigList.PrintList(lboxFigures);
             FigList.DrawAll(grMajor);
             grRez.DrawImage(Layers[2], 0, 0);
             pictureBox1.Refresh();
             btnBack.Enabled = false;
         }
     }
     rbPointer.Checked = true;
 }
示例#5
0
        private void btnMkUsrFig_Click(object sender, EventArgs e)
        {
            isOpenFile = true;
            string name = Microsoft.VisualBasic.Interaction.InputBox("Creating figure...", "Enter name:");

            {
                if (name != "")
                {
                    if (!IsExistName(name))
                    {
                        FileStream fs = new FileStream(Application.StartupPath.ToString() + "\\" + UserFiguresPath + "\\" + name + "." + UserFiguresExtension,
                                                       FileMode.OpenOrCreate, FileAccess.ReadWrite);
                        userfigsbinser = new MyCustomFiguresBinarySerializer();
                        var transformer = new UserFiguresTransformer();
                        var tmplist     = transformer.TransformToFullList(FigList);
                        userfigsbinser.SaveFiguresList(fs, tmplist);
                        fs.Close();

                        for (int i = 0; i < tmplist.Size(); i++)
                        {
                            usrlst.Add(tmplist.Item(i).Copy());
                        }

                        SourceLists.Add(usrlst);
                        typ = Type.GetType("Lab1.UserFigure");
                        var nextRB = new RadioButton();
                        nextRB.Parent = grboxFigures;
                        nextRB.Left   = 8;
                        nextRB.Top    = StartRBPos;
                        StartRBPos   += 27;
                        nextRB.Width  = 100;
                        nextRB.Height = 21;
                        nextRB.Text   = name;
                        UserNamesList.Add(name);

                        nextRB.CheckedChanged += (a, b) =>
                        {
                            try
                            {
                                CurrentList = usrlst;
                                CurrentName = name;
                                FigParams   = new Object[] { CurrentName, CurrentList, CurrPen, 0, 0, 0, 0 };
                                figure      = (Figure.Figure)Activator.CreateInstance(typ, FigParams);
                                isChanged   = true;
                                isPointer   = false;
                            }
                            catch (Exception ee)
                            {
                                MessageBoxException(ee.Message);
                            }
                        };
                    }
                    else
                    {
                        MessageBoxError("Such name is already exist.", "Error");
                    }
                }
                else
                {
                    MessageBoxError("Field couldn't be empty.", "Error");
                }
            }
            isOpenFile = false;
        }