Example #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;
            }
        }
Example #2
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;
 }
Example #3
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;
        }