private void DrawPanel_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Middle) { midDown = false; } else if (e.Button == MouseButtons.Right) { rightDown = false; if (mouseDown.X < mouseUp.X) //保证该box Xmin,Xmax不弄反。 { box.Xmin = mouseDown.X; box.Xmax = mouseUp.X; } else { box.Xmin = mouseUp.X; box.Xmax = mouseDown.X; } if (mouseDown.Y < mouseUp.Y) { box.Ymin = mouseDown.Y; box.Ymax = mouseUp.Y; } else { box.Ymin = mouseUp.Y; box.Ymax = mouseDown.Y; } } DrawPanel.Cursor = Cursors.Cross; leftDown = false; DrawPanel.Refresh(); }
private void Start() { gameManager = GameObject.FindGameObjectWithTag("GameManager"); mainMenu = GameObject.FindGameObjectWithTag("MainMenu"); mainMenuScript = mainMenu.GetComponent <MainMenu>(); drawPanelScript = GameObject.FindGameObjectWithTag("DrawPanel").GetComponent <DrawPanel>(); createRandomMenu = GameObject.FindGameObjectWithTag("CreateRandomMenu"); createRandomScript = createRandomMenu.GetComponent <MainMenu>(); templateMenu = GameObject.FindGameObjectWithTag("TemplateMenu"); templateMenuScript = templateMenu.GetComponent <MainMenu>(); slider = GameObject.FindGameObjectWithTag("Slider"); sliderScript = slider.GetComponent <MainMenuSlider>(); tooltips = GameObject.FindGameObjectsWithTag("Tooltip"); selectorControls = GameObject.FindGameObjectWithTag("SelectorControls"); selectorControlsScript = selectorControls.GetComponent <SelectorMenuControls>(); selector = GameObject.FindGameObjectWithTag("Selector"); menus.AddLast(mainMenuScript); menus.AddLast(createRandomScript); menus.AddLast(templateMenuScript); menus.AddLast(selectorControlsScript); panels.AddLast(drawPanelScript); HideTooltips(); CloseAllMenus(); selector.SetActive(false); StartCoroutine(StartTooltips()); }
/// <summary> /// 开始与暂停 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void StartStopBtn_Click(object sender, EventArgs e) { if (ViewModule.IsRecording) { if (writer != null) { writer.Close(); } capture.StopRecording(); if (IsSaveFile.Checked) { FileNameContent.Text += "(Saved)"; } } else { if (bufferedGraphics == null) { bufferedGraphics = BufferedGraphicsManager.Current.Allocate(DrawPanel.CreateGraphics(), DrawPanel.ClientRectangle); } if (IsSaveFile.Checked) { string filename = Path.GetFileName(Path.GetRandomFileName()) + ".wav"; writer = new WaveFileWriter(filename, capture.WaveFormat); FileNameContent.Text = filename; } capture.StartRecording(); } ViewModule.IsRecording ^= true; }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Png files| *.png| jpeg files| *jpg| bitmaps| *bmp"; if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { Bitmap pmOp = new Bitmap(open.FileName); //shape.bm = new Bitmap(pmOp.Width, pmOp.Height); //shape.bm = pmOp; // //Image im = (Image)shape.bm; DrawPanel.Width = pmOp.Width; DrawPanel.Height = pmOp.Height; Graphics graphics; //DrawPanel.BackgroundImage = shape.bm; graphics = DrawPanel.CreateGraphics(); //shape.g = Graphics.FromImage(im); graphics.DrawImage(pmOp, 0, 0, pmOp.Width, pmOp.Height); graphics.Dispose(); pmOp.Dispose(); } catch (Exception ex) { MessageBox.Show("Error loading image " + ex.Message); } } }
public Form1() { InitializeComponent(); theWorld = new World(); SeverInput.Text = "localhost"; ClientSize = new Size(WorldSize, WorldSize); drawingPanel = new DrawPanel(theWorld); drawingPanel.Location = new Point(0, 0); drawingPanel.Size = new Size(this.ClientSize.Width, this.ClientSize.Height); drawingPanel.BackColor = Color.Black; sc = new Score(theWorld); sc.Location = new Point(ClientSize.Width, 0); sc.Size = new Size(300, this.ClientSize.Height); sc.BackColor = Color.WhiteSmoke; ClientSize = new Size(WorldSize + sc.Size.Width, WorldSize); this.Controls.Add(sc); this.Controls.Add(drawingPanel); }
public void DrawPolyPoints(List <MyPoint> pts) { try { int h = 0; int xmax = 0, xmin = 0, ymax = 0, ymin = 0; FindEdgePoints(pts, ref xmax, ref xmin, ref ymax, ref ymin); SysCoord(xmax, xmin, ymax, ymin, ref h); PointF[] PolyPts = new PointF[pts.Count]; for (int i = 0; i < pts.Count; i++) { PolyPts[i] = new PointF(Center(pts[i].x, h), Center(-pts[i].y, h)); } using (Graphics g = DrawPanel.CreateGraphics()) { using (Pen p = new Pen(ColorPoint, SizePoint)) { DrawVertexes(g, p, h, pts); p.Color = ColorEdge; p.Brush = new SolidBrush(ColorEdge); p.Width = SizeEdge; g.DrawPolygon(p, PolyPts); } } } catch (Exception e) { MessageBox.Show(e.Message + '\n' + '\r' + e.StackTrace, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Calculate_Click(object sender, EventArgs e) { if (PointsN < 3) { MessageBox.Show("Введено слишком мало точек! Минимум 3 точки."); return; } string[] a = new String[PointsN]; int i = 0; foreach (object x in VertexesBox.Items) { a[i++] = (String)x; } double Square = 0; List <MyPoint> pts = new List <MyPoint>(); if (Find3DPolygon.CalculatePolySq(a, ref Square, ref pts)) { OutputBox.Text = "Итак, программа получила, что:\nПлощадь = " + Square + "\nМногоугольник сосотоит из " + pts.Count + " точек."; LastPolyPts = pts; PolyCreated = true; DrawPanel.Refresh(); DrawPolyPoints(LastPolyPts); } else { MessageBox.Show("Ошибка: не удалось вычислить площадь при заданных вершинах!"); } }
private void DrawPanel_MouseClick(object sender, MouseEventArgs e) { DrawPanel.Focus(); PointList.Add(new Point(e.X, e.Y)); CanCreateFigure(); }
private void MapEventHappened(object sender, MapEventArgs e) { switch (e.EventType) { case MapEventType.MapViewChanged: { CentrXY = e.CentrXY; CentrOffset = e.CentrOffset; ActiveOffset = e.ActiveOffset; PanelMap_offset = e.PanelMap_offset; MapPanel_offset = e.MapPanel_offset; MapRect1 = e.MapRect1; MapRect2 = e.MapRect2; DrawPanel.Refresh(); break; } case MapEventType.ToggleBetweenCurrentEntireMapView: { DrawPanel.Refresh(); break; } default: break; } }
private void DrawPanel_MouseMove(object sender, MouseEventArgs e) { PointF[] mousePo = { new PointF(e.X, e.Y) }; if (mat != null) { mat.TransformPoints(mousePo); } mouseUp = mousePo[0]; lblX.Text = "X:" + String.Format("{0:F}", mousePo[0].X); lblY.Text = "Y:" + String.Format("{0:F}", mousePo[0].Y); if (e.Button == MouseButtons.Middle) { float dx = mouseUp.X - mouseDown.X; float dy = mouseUp.Y - mouseDown.Y; mouseUp = mousePo[0]; box.Xmin -= dx; box.Xmax -= dx; box.Ymin -= dy; box.Ymax -= dy; } else if (e.Button == MouseButtons.Right) { mouseUp = mousePo[0]; } DrawPanel.Refresh(); }
private void ClearBt_Click(object sender, EventArgs e) { DrawPanel.Focus(); UHierarchy.ClearHierarchy(); DPanel.Clear(Panel.DefaultBackColor); UHierarchy.UpdatePanel(DPanel); }
private void DrawPanel_Click(object sender, EventArgs e) { saved = false; int x = GetCursorX(); int y = GetCursorY(); if (tsbPicker.Checked) { tsbColorPicker.Color = pixels[x, y]; tsbPicker.Checked = false; tsbDraw.Checked = true; } else if (tsbFill.Checked || tsbTexturize.Checked) { BackupForUndo(); if (tsbFill.Checked) { Fill(x, y); } else if (tsbTexturize.Checked) { Texturize(x, y); } DrawPanel.Refresh(); } }
/* ------------------------------------------------------------------------------- * Constructor: Form1 * * Use: Constructs a new Dirived Form object. * * Parameters: none * -------------------------------------------------------------------------------*/ public Form1() { InitializeComponent(); //Generate a new graphics object for displaying images g = DrawPanel.CreateGraphics(); //Creates a new bitmap that is the same size as the drawing field, and sets it to all white Canvas = new Bitmap(DrawPanel.Size.Width, DrawPanel.Size.Height); DrawPanel.DrawToBitmap(Canvas, new Rectangle(0, 0, DrawPanel.Size.Width, DrawPanel.Size.Height)); //Generate a new graphics object for saving images bitmapg = Graphics.FromImage(Canvas); //Initialize Variables. DrawCurrentColor = Color.Black; DrawBackgroundColor = Color.White; BackgroundButton.BackColor = Color.White; RecentFiles.Add(SaveHold1); RecentFiles.Add(SaveHold2); RecentFiles.Add(SaveHold3); RecentFiles.Add(SaveHold4); RecentFiles.Add(SaveHold5); }
private void StartAnimation(AnimationType anim) { switch (anim) { case AnimationType.UpdateMap: animationTimer.Stop(); AnimationCount = 0; DrawPanel.Invalidate(); break; case AnimationType.UnitWaiting: animationTimer.Stop(); AnimationFrames = GetAnimationFrames.UnitWaiting(_main.ViewPieceMode); AnimationCount = 0; animationTimer.Interval = 200; // ms animationTimer.Start(); break; case AnimationType.UnitMoving: //AnimType = AnimationType.UnitMoving; AnimationFrames = GetAnimationFrames.UnitMoving(_main.ViewPieceMode); break; case AnimationType.ViewPiece: animationTimer.Stop(); AnimationCount = 0; animationTimer.Interval = 200; // ms animationTimer.Start(); break; } }
// open image when any of recent image clicked private void RecentImagesClick(object sender, EventArgs e) { if (drawLines.Any() || redoLines.Any()) { ShowUnsavedChangesWarning(sender, e); } var image = (ToolStripMenuItem)sender; Image img; if (!File.Exists(image.Text)) { MessageBox.Show("Could not open file: " + image.Text + ".\n\nNo such file exists!"); return; } using (var bmpTemp = new Bitmap(image.Text)) { img = new Bitmap(bmpTemp); } DrawPanel.BackgroundImage = img; drawLines.Clear(); Undo.Enabled = false; redoLines.Clear(); Redo.Enabled = false; DrawPanel.Invalidate(); fileName = image.Text; UpdateRecent(fileName); }
private void DrawPanel_MouseWheel(object sender, MouseEventArgs e) { if ((Keyboard.GetKeyStates(Key.LeftCtrl) & KeyStates.Down) > 0) { ((HandledMouseEventArgs)e).Handled = true; if (e.Delta > 0) { scale *= 1.3; } else { scale /= 1.3; } if (scale < 1) { scale = 1; } if (scale > 30) { scale = 30; } AdjustDrawPanel(); DrawPanel.Refresh(); } }
public GameEngine(Form form, int width = 500, int height = 500) { this.Form = form; this.Form.FormBorderStyle = FormBorderStyle.Fixed3D; // Double Buffering DrawPanel panel = new DrawPanel(width, height); Form.Controls.Add(panel); // No Resizing this.Form.MaximizeBox = false; //this.form.MinimizeBox = false; this.Form.ClientSize = new Size(width, height); // Size of form g = panel.CreateGraphics(); worldManager = new WorldManager(this); fps = 0; KeyHandler = new KeyHandler(form); // Add Closing Event form.FormClosing += (sender, args) => Stop(); ticks = new Dictionary <TickSchedule, List <Action> >(); foreach (TickSchedule t in Enum.GetValues(typeof(TickSchedule))) { ticks[t] = new List <Action>(); } }
private void DrawPanel_MouseClick(object sender, MouseEventArgs e) { var figure = new FigureClass { x = e.X, y = e.Y, borderColor = _borderColor, fillColor = _fillColor, size = _size }; switch (_figure) { case Figure.Circle: _circleCoords.Add(figure); break; case Figure.Square: _squaresCoords.Add(figure); break; case Figure.Triangle: _triangesCoords.Add(figure); break; default: break; } DrawPanel.Update(); DrawPanel.Refresh(); }
// When an option is clicked, update the bool array of options private void ClickPanels_Click(object sender, EventArgs e) { Control clickedControl = (Control)sender; // Sender gives you which control is clicked. int index = _clickPanels.FindIndex(a => a == clickedControl); // Get which control is clicked in a list _choiceOptions[index] = !_choiceOptions[index]; DrawPanel.Invalidate(); }
public static Color fillColor; // public Form1() { InitializeComponent(); primitive = new Pencil(DrawPanel.CreateGraphics()); p = new Pen(Color.Black, (float)trackBarThickness.Value); fillColor = Color.Black; // buttonInvert.Click += MakeWork; }
private void DrawPanel_Paint(object sender, PaintEventArgs e) { System.Drawing.Pen linepen; linepen = new System.Drawing.Pen(System.Drawing.Color.Black); System.Drawing.Graphics g = DrawPanel.CreateGraphics(); g.DrawLine(linepen, 0, DrawPanel.Height / 2, DrawPanel.Width, DrawPanel.Height / 2); g.DrawLine(linepen, DrawPanel.Width / 2, 0, DrawPanel.Width / 2, DrawPanel.Height); }
/* ------------------------------------------------------------------------------- * Function: ColorButton_Click * * Use: Changes the current color * * Parameters: Sender: Refrence to the object that called this function * EventArgs: The auguments passed from the calling object * * Returns: nothing * -------------------------------------------------------------------------------*/ private void ColorButton_Click(object sender, EventArgs e) { //gets the color of the clicked box, and sets The current color to it TextBox ClickedBox = (TextBox)sender; DrawCurrentColor = ClickedBox.BackColor; DrawPanel.Focus(); }
private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == (char)Keys.Enter) { CanCreateFigure(true); DrawPanel.Focus(); } }
public MainForm() { InitializeComponent(); _graphics = DrawPanel.CreateGraphics(); StopBtn.Enabled = false; SimBackgroundWorker.WorkerSupportsCancellation = true; SimBackgroundWorker.WorkerReportsProgress = true; }
/* ------------------------------------------------------------------------------- * Function: newToolStripMenuItem_Click * * Use: Clears the currently Drawn Image * * Parameters: Sender: Refrence to the object that called this function * EventArgs: The auguments passed from the calling object * * Returns: nothing * -------------------------------------------------------------------------------*/ private void newToolStripMenuItem_Click(object sender, EventArgs e) { //If anything is drawn, or if the user hasn't saved, ask if they would like to if (AnythingDrawn) { if (MessageBox.Show("Would you like to save your progress?", "Save?", MessageBoxButtons.YesNo) == DialogResult.Yes) { saveToolStripMenuItem_Click(sender, e); } } //save Current filename for most recent files if (CurrentSaveName != null) { if (PositionInRecentFileArray == 5) { PositionInRecentFileArray = 0; } RecentFiles[PositionInRecentFileArray].Text = CurrentSaveName; RecentFiles[PositionInRecentFileArray].Enabled = true; PositionInRecentFileArray++; CurrentSaveName = null; } //Reset anythingdrawn flag & defaults AnythingDrawn = false; DrawBackgroundColor = Color.White; BackgroundButton.BackColor = Color.White; //reset resources Canvas.Dispose(); Canvas = new Bitmap(DrawPanel.Size.Width, DrawPanel.Size.Height); bitmapg.Dispose(); //clear stacks while (RedoStack.Any()) { RedoStack.Pop().Dispose(); } while (UndoStack.Any()) { UndoStack.Pop().Dispose(); } //reset buttons RedoButton.Enabled = false; UndoButton.Enabled = false; //this works because the "CreateGraphics" is not persistent & DrawPanel will always be 'blank' DrawPanel.DrawToBitmap(Canvas, new Rectangle(0, 0, DrawPanel.Size.Width, DrawPanel.Size.Height)); bitmapg = Graphics.FromImage(Canvas); //Redraw our canvas on drawpanel g.DrawImage(Canvas, Point.Empty); }
private void ClearBtn_Click(object sender, EventArgs e) { _circleCoords.Clear(); _squaresCoords.Clear(); _triangesCoords.Clear(); DrawPanel.Update(); DrawPanel.Refresh(); }
public static Control FindControlAtCursor(DrawPanel dp) { Point pos = Cursor.Position; if (dp.Bounds.Contains(pos)) { return(FindControlAtPoint(dp, dp.PointToClient(pos))); } return(null); }
private void MapViewChange(int[] newCenterCoords) { if (map != null) { map.Dispose(); } ReturnCoordsAtMapViewChange(newCenterCoords); map = Draw.MapPart(Game.ActiveCiv.Id, mapStartXY[0], mapStartXY[1], mapDrawSq[0], mapDrawSq[1], Game.Zoom, Game.Options.FlatEarth); DrawPanel.Invalidate(); }
public void ZoomOUTclicked(Object sender, EventArgs e) { if (Game.Zoom != 8) { Game.Zoom--; MapViewChange(CentrXY); StartAnimation(AnimType); DrawPanel.Invalidate(); } }
private void SaveDrawing() { Bitmap pasPerdre = new Bitmap(DrawPanel.Width, DrawPanel.Height); Graphics g = Graphics.FromImage(pasPerdre); Rectangle rect = DrawPanel.RectangleToScreen(DrawPanel.ClientRectangle); g.CopyFromScreen(rect.Location, Point.Empty, DrawPanel.Size); g.Dispose(); DrawPanel.BackgroundImage = pasPerdre; }