private void LoadDll_Click_(object sender, EventArgs e) { if (openDllDialog.ShowDialog() == DialogResult.OK) { AppDomain ad = AppDomain.CurrentDomain; ad.AssemblyResolve += MyHandler; var plug = typeof(IFiguresCreator); // byte[] bytes = File.ReadAllBytes(openDllDialog.FileName); Assembly assembly; try { assembly = ad.Load(openDllDialog.FileName); } catch { MessageBox.Show("Данная сборка уже загружена"); return; } Type[] types = assembly.GetTypes(); bool IFiguresExist = false; for (int i = 0; i < types.Length; i++) { if (plug.IsAssignableFrom(types[i])) { try { IFiguresCreator Tmp = (IFiguresCreator)Activator.CreateInstance(types[i]); Creators.AddLast(((IFiguresCreator)Activator.CreateInstance(types[i]))); comboBox1.Items.Add(Creators.Last <IFiguresCreator>().Name); } catch (Exception ex) { MessageBox.Show(ex.Message); } IFiguresExist = true; } } if (!IFiguresExist) { MessageBox.Show("Подходящих ресурсов не найдено."); } } }
private void panel1_MouseDown(object sender, MouseEventArgs e) { if (CurrentFigure == null) { IFiguresCreator CurrentCreator = Creators.ElementAt <IFiguresCreator>(comboBox1.SelectedIndex); CurrentFigure = CurrentCreator.Create(-1, -1, gr, pen, FillColorPanel.BackColor); } CurrentFigure.StartPoint = new Point(e.X, e.Y); PreDrawTimer.Enabled = true; FpsCounter = 0; timer1.Enabled = true; }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { numericUpDown1.Visible = false; TopsLabel.Visible = false; label2.Visible = false; IFiguresCreator CurrentCreator = Creators.ElementAt <IFiguresCreator>(comboBox1.SelectedIndex); CurrentFigure = CurrentCreator.Create(-1, -1, gr, pen, FillColorPanel.BackColor); if (CurrentCreator.TopsNeeded) { numericUpDown1.Visible = true; TopsLabel.Visible = true; } if (FiguresBackBuffer.Count > 0) { FiguresBackBuffer.ElementAt(0).EndOfCurrentFigure = true; } }
private void button1_Click(object sender, EventArgs e) { int N = FiguresBackBuffer.Count; if (N <= 0) { return; } if (FiguresFrontBuffer == null) { FiguresFrontBuffer = new UndoStack(); } IFigure Last = FiguresBackBuffer.ElementAt(0); Last.EndOfCurrentFigure = true; FiguresFrontBuffer.Push(Last); FiguresBackBuffer.Pop(); RedoButton.Enabled = true; gr = Graphics.FromImage(MainPicture); gr.Clear(pictureBox1.BackColor); FiguresBackBuffer.DrawStack(gr); pictureBox1.Image = MainPicture; if (FiguresBackBuffer.Count <= 0) { UndoButton.Enabled = false; } IFiguresCreator CurrentCreator = Creators.ElementAt <IFiguresCreator>(comboBox1.SelectedIndex); CurrentFigure = CurrentCreator.Create(-1, -1, gr, pen, FillColorPanel.BackColor); }