Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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;
 }