/// <summary> /// Creates an empty SpreadsheetPanel /// </summary> public SpreadsheetPanel() { InitializeComponent(); // The DrawingPanel is quite large, since it has 26 columns and 99 rows. The // SpreadsheetPanel itself will usually be smaller, which is why scroll bars // are necessary. drawingPanel = new DrawingPanel(this); drawingPanel.Location = new Point(0, 0); drawingPanel.AutoScroll = false; // A custom vertical scroll bar. It is designed to scroll in multiples of rows. vScroll = new VScrollBar(); vScroll.SmallChange = 1; vScroll.Maximum = ROW_COUNT; // A custom horizontal scroll bar. It is designed to scroll in multiples of columns. hScroll = new HScrollBar(); hScroll.SmallChange = 1; hScroll.Maximum = COL_COUNT; MinimumSize = new Size(2, 2); // Add the drawing panel and the scroll bars to the SpreadsheetPanel. Controls.Add(drawingPanel); Controls.Add(vScroll); Controls.Add(hScroll); // Arrange for the drawing panel to be notified when it needs to scroll itself. hScroll.Scroll += drawingPanel.HandleHScroll; vScroll.Scroll += drawingPanel.HandleVScroll; // Create the spreadsheet object s = new Spreadsheet(s => true, s => s.ToUpper(), "ps6"); }
/// <summary> /// Creates an empty SpreadsheetPanel /// </summary> public SpreadsheetPanel() { InitializeComponent(); // The DrawingPanel is quite large, since it has 26 columns and 99 rows. The // SpreadsheetPanel itself will usually be smaller, which is why scroll bars // are necessary. drawingPanel = new DrawingPanel(this); drawingPanel.Location = new Point(0, 0); drawingPanel.AutoScroll = false; SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.Transparent; // A custom vertical scroll bar. It is designed to scroll in multiples of rows. vScroll = new VScrollBar(); vScroll.SmallChange = 1; vScroll.Maximum = ROW_COUNT; // A custom horizontal scroll bar. It is designed to scroll in multiples of columns. hScroll = new HScrollBar(); hScroll.SmallChange = 1; hScroll.Maximum = COL_COUNT; // Add the drawing panel and the scroll bars to the SpreadsheetPanel. Controls.Add(drawingPanel); Controls.Add(vScroll); Controls.Add(hScroll); // Arrange for the drawing panel to be notified when it needs to scroll itself. hScroll.Scroll += drawingPanel.HandleHScroll; vScroll.Scroll += drawingPanel.HandleVScroll; }
private void StartButton_Click(object sender, EventArgs e) { if (StartButton.Text == "Start") { AnimationTimer.Enabled = true; StartButton.Text = "Stop"; x1 = rnd.Next(0, DrawingPanel.Width); x2 = rnd.Next(0, DrawingPanel.Width); y1 = rnd.Next(0, DrawingPanel.Height); y2 = rnd.Next(0, DrawingPanel.Height); x1inc = rnd.Next(4, 15); x2inc = rnd.Next(4, 15); y1inc = rnd.Next(4, 15); y2inc = rnd.Next(4, 15); Graphics g = DrawingPanel.CreateGraphics(); g.Clear(Color.Black); // Clear the screen g.Dispose(); lines = new List <Line>(); } else { AnimationTimer.Enabled = false; StartButton.Text = "Start"; } }
// Called when form refreshed, redraws graph based on selection private void DrawingPanel_Paint(object sender, PaintEventArgs e) { Graph graph = graphs[cboxMonthDataTypes.SelectedIndex]; // Used to set up appropriate axes float overallRange = graph.YearMaxValue - graph.YearMinValue; // Graph size remains constant float pixelsPerUnit = maxBarLength / overallRange; using (Graphics panelGraphics = DrawingPanel.CreateGraphics()) using (SolidBrush writeBrush = new SolidBrush(fontColor)) { DrawVerticalGraphIntervals(graph, panelGraphics, writeBrush, pixelsPerUnit); if (graph is BoxPlotGraph boxPlotGraph) { DrawBoxPlotGraph(panelGraphics, writeBrush, overallRange, pixelsPerUnit, boxPlotGraph); } else { DrawSimpleBarGraph(graph, panelGraphics, writeBrush, pixelsPerUnit); } DrawAxes(graph, panelGraphics, writeBrush); } }
private void DrawingPanel_MouseClick(object sender, MouseEventArgs e) { if (GameTimer.Enabled) { // TODO – Check if we clicked on a Ball // do this by iterating through list of balls and check using the PointInBall method for (int i = 0; i < NumberOfBalls; i++) { // if (e,X, e.Y) is inside the Ball, remove from List and then // clear the objects and redraw the remaining objects on screen. if (ballList[i].PointInBall(e.X, e.Y)) { ballList.RemoveAt(i); NumberOfBalls--; } } Graphics g = DrawingPanel.CreateGraphics(); //Create a graphics object // TODO – Add code to draw all of the Balls in the list to the screen g.Clear(Color.Black); foreach (Ball b in ballList) { b.Draw(g); } } }
private void RunButton_Click(object sender, EventArgs e) { bool czy = int.TryParse(LevelsBox.Text, out n); if (czy) { if (n <= 0) { MessageBox.Show(Nazwy.emsgSierpinskiPoziomy, Nazwy.eBłąd, MessageBoxButtons.OK, MessageBoxIcon.Error); n = 8; LevelsBox.Text = "8"; } } else { MessageBox.Show(Nazwy.emsgSierpinskiPoziomy, Nazwy.eBłąd, MessageBoxButtons.OK, MessageBoxIcon.Error); n = 8; LevelsBox.Text = "8"; } WasClicked = true; DrawingPanel.Refresh(); }
/// <summary> /// Creates an empty SpreadsheetPanel /// </summary> public SpreadsheetPanel() { InitializeComponent(); // The DrawingPanel is quite large, since it has 26 columns and 99 rows. The // SpreadsheetPanel itself will usually be smaller, which is why scroll bars // are necessary. drawingPanel = new DrawingPanel(this); drawingPanel.Location = new Point(0, 0); drawingPanel.AutoScroll = false; // A custom vertical scroll bar. It is designed to scroll in multiples of rows. vScroll = new VScrollBar(); vScroll.SmallChange = 1; vScroll.Maximum = ROW_COUNT; // A custom horizontal scroll bar. It is designed to scroll in multiples of columns. hScroll = new HScrollBar(); hScroll.SmallChange = 1; hScroll.Maximum = COL_COUNT; // Add the drawing panel and the scroll bars to the SpreadsheetPanel. Controls.Add(drawingPanel); Controls.Add(vScroll); Controls.Add(hScroll); // Arrange for the drawing panel to be notified when it needs to scroll itself. hScroll.Scroll += drawingPanel.HandleHScroll; vScroll.Scroll += drawingPanel.HandleVScroll; // The spreadsheet model that tracks dependencies, stores contents of cells, and calculates values etc. sp = new Spreadsheet(s => IsValid(s), s => s, "1.00.00"); }
//Detects if player has hit fruit static void HitDetection(Graphics g, DrawingPanel panel, int x, int y, int length) { for (int i = 0; i < length; i++) { if (x == snakePossibleLengthX[i]) { if (y == snakePossibleLengthY[i]) { panel.RefreshDisplay(); g.DrawString("Game Over", font1, Brushes.Black, 300, 165); g.DrawString($"Final Score: {fruitEaten - 1}", font1, Brushes.Black, 300, 200); panel.RefreshDisplay(); Thread.Sleep(5000); Environment.Exit(1); } } } if (x > fruitX - 20 && x < fruitX + 20) { Fruit(g, panel, false); if (y > fruitY - 20 && y < fruitY + 20) { Fruit(g, panel, true); fruitEaten++; } } else { Fruit(g, panel, false); } }
//Increases snakes length static void SnakeLengthIncrease(Graphics g, DrawingPanel panel, int length) { int x = snakePossibleLengthX[length]; int y = snakePossibleLengthY[length]; g.FillRectangle(Brushes.Red, x, y, 25, 25); }
//Repeats "SnakeLengthIncrease" based on snake's length static void NumberOfSnakeLength(Graphics g, DrawingPanel panel, int length) { for (int i = 0; i < length; i++) { SnakeLengthIncrease(g, panel, i); } }
private void DrawingPanel_MouseClick(object sender, MouseEventArgs e) { if (GameTimer.Enabled) { for (int i = 0; i < NumberOfBalls; i++) { if (ballList[i].PointInBall(e.X, e.Y)) { ballList.RemoveAt(i); NumberOfBalls--; } } Graphics g = DrawingPanel.CreateGraphics(); //Create a graphics object g.Clear(Color.Black); foreach (Ball b in ballList) { b.Draw(g); } g.Dispose(); } }
private void AnimationTimer_Tick(object sender, EventArgs e) { //Graphics objects for drawing lines. Graphics g = DrawingPanel.CreateGraphics(); if (yValue < 155) { //Clear lines and liquid stream with rectangles. yValue = 374; g.FillRectangle(blackBrush, 91, 150, 249, 225); g.FillRectangle(blackBrush, 215, 118, 25, 256); //Reset the TrackBar and Timer. SpeedTrackBar.Value = 0; AnimationTimer.Enabled = false; } else { //Drawing a line at each tick interval. Line nextLine = new Line(91, yValue, 339, yValue, liquidColor); nextLine.Draw(g); //Liquid stream must be redrawn according to the color change. g.FillRectangle(new SolidBrush(liquidColor), 215, 118, 25, yValue - 118); } yValue--; //Disposing Graphics object after drawing a line on or resetting the DrawingPanel. g.Dispose(); }
void LateUpdate() { if (takeScreenshot) { Camera camera = gameObject.GetComponent <Camera>(); camera.pixelRect = new Rect(0, 0, Screen.width, Screen.height); RenderTexture rt = new RenderTexture(screenshotSize, screenshotSize, 24); camera.targetTexture = rt; Texture2D screenShot = new Texture2D(screenshotSize, screenshotSize, TextureFormat.RGB24, false); camera.Render(); RenderTexture.active = rt; screenShot.ReadPixels(new Rect(0, 0, screenshotSize, screenshotSize), 0, 0); camera.targetTexture = null; RenderTexture.active = null; // JC: added to avoid errors Destroy(rt); int[][] values = new int[screenShot.width][]; for (int x = 0; x < screenShot.width; x++) { values[x] = new int[screenShot.height]; for (int y = 0; y < screenShot.height; y++) { values[x][y] = DrawingPanel.ColorToInt(screenShot.GetPixel(x, screenShot.height - y - 1)); } } takeScreenshot = false; ProjectPanel.GetComponent <ProjectPanel>().SetTerrainThumbnail(values); if (rectTransform != null) { SetCameraViewport(rectTransform); } } }
private void RunButton_Click(object sender, EventArgs e) { bool czy = int.TryParse(InputBox.Text, out IloscPunktow); if (czy) { if (IloscPunktow < 1) { MessageBox.Show(Nazwy.emsgAproksymacjaPunkty, Nazwy.eBłąd, MessageBoxButtons.OK, MessageBoxIcon.Error); IloscPunktow = 2000; InputBox.Text = "2000"; } } else { MessageBox.Show(Nazwy.emsgAproksymacjaPunkty, Nazwy.eBłąd, MessageBoxButtons.OK, MessageBoxIcon.Error); IloscPunktow = 2000; InputBox.Text = "2000"; } WasClicked = true; OutputBox.Text = ""; DrawingPanel.Refresh(); }
/// <summary> /// Creates an empty SpreadsheetPanel /// </summary> public SpreadsheetPanel() { InitializeComponent(); // The DrawingPanel is quite large, since it has 26 columns and 99 rows. The // SpreadsheetPanel itself will usually be smaller, which is why scroll bars // are necessary. drawingPanel = new DrawingPanel(this); drawingPanel.Location = new Point(0, 0); drawingPanel.AutoScroll = false; // A custom vertical scroll bar. It is designed to scroll in multiples of rows. vScroll = new VScrollBar(); vScroll.SmallChange = 1; vScroll.Maximum = ROW_COUNT; // A custom horizontal scroll bar. It is designed to scroll in multiples of columns. hScroll = new HScrollBar(); hScroll.SmallChange = 1; hScroll.Maximum = COL_COUNT; // Add the drawing panel and the scroll bars to the SpreadsheetPanel. Controls.Add(drawingPanel); Controls.Add(vScroll); Controls.Add(hScroll); // Arrange for the drawing panel to be notified when it needs to scroll itself. hScroll.Scroll += drawingPanel.HandleHScroll; vScroll.Scroll += drawingPanel.HandleVScroll; }
public MainForm() { InitializeComponent(); Load(); g = DrawingPanel.CreateGraphics(); timer.Interval = 1000; InitNewGeneration(); timer.Tick += (s, e) => { if (best != null && best.Alive) { DrawSnake(); best.Step(); } else { InitNewGeneration(); } }; }
/// <summary> /// Event handler for the Save button click event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void SaveButton_Clicked(object sender, RoutedEventArgs e) { if (!DrawingPanel.HasContent) { rootPage.NotifyUser("Must have content before saving.", NotifyType.ErrorMessage); return; } // Saves the current drawing to a GIF-compatible file the user selects. FileSavePicker picker = new FileSavePicker(); picker.FileTypeChoices.Add(new KeyValuePair <string, IList <string> >("SCPDraw", new List <string>() { DefaultFileExtension })); picker.DefaultFileExtension = DefaultFileExtension; picker.SuggestedFileName = "drawing"; picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; var file = await picker.PickSaveFileAsync(); if (file != null) { using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite)) { await DrawingPanel.SaveStrokesToStreamAsync(stream); } rootPage.NotifyUser("Saved drawing to file: " + file.Name, NotifyType.StatusMessage); } }
/// <summary> /// Event handler for the Replay button click event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ReplayButton_Clicked(object sender, RoutedEventArgs e) { // Replays a previously saved drawing, drawing each strokein the order the author originally drew them. FileOpenPicker picker = new FileOpenPicker(); picker.FileTypeFilter.Add(DefaultFileExtension); picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; var file = await picker.PickSingleFileAsync(); if (file != null) { using (var stream = await file.OpenAsync(FileAccessMode.Read)) { // Draw each stroke segment over a 50ms interval. try { DrawingPanel.BeginStrokesReplayFromStream(stream, 50); } catch (Exception) { rootPage.NotifyUser("Unable to load file.", NotifyType.ErrorMessage); } } } }
/// <summary> /// Event handler for the Load button click event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void LoadButton_Clicked(object sender, RoutedEventArgs e) { // Loads a previously saved drawing. FileOpenPicker picker = new FileOpenPicker(); picker.FileTypeFilter.Add(DefaultFileExtension); picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; var file = await picker.PickSingleFileAsync(); if (file != null) { using (var stream = await file.OpenAsync(FileAccessMode.Read)) { try { await DrawingPanel.LoadStrokesFromStreamAsync(stream); DrawingPanel.Update(); } catch (Exception) { rootPage.NotifyUser("Unable to load file.", NotifyType.ErrorMessage); } } } }
private void Sierpinski_Resize(object sender, EventArgs e) { var width = this.Width; var height = this.Height - panel1.Height; DrawingPanel.Size = new Size(width, height); DrawingPanel.Refresh(); }
public ChessPanel() { InitializeComponent(); drawingPanel = new DrawingPanel(this); drawingPanel.Location = new Point(0, 0); Controls.Add(drawingPanel); }
public MainWindow() { InitializeComponent(); WindowSize = DrawingPanel.Width; SingleSquareSize = WindowSize / (float)Settings.BoardSize - (float)(1.7 / (float)Settings.BoardSize); drawArea = DrawingPanel.CreateGraphics(); }
private void DrawingPanel_Paint(object sender, PaintEventArgs e) { Graphics g = DrawingPanel.CreateGraphics(); g.Clear(Color.White); level.setGraphics(g, DrawingPanel.Size.Width); this.g = g; }
private void InfoUpdate() { // Get the current raw sensor KG values. var rwWeight = wiiDevice.WiimoteState.BalanceBoardState.WeightKg; var rwTopLeft = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.TopLeft; var rwTopRight = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.TopRight; var rwBottomLeft = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft; var rwBottomRight = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.BottomRight; float pointX = wiiDevice.WiimoteState.BalanceBoardState.CenterOfGravity.X; float pointY = wiiDevice.WiimoteState.BalanceBoardState.CenterOfGravity.Y; // label_rwWT.Text = rwWeight.ToString("0.0"); LeftTopVal.Text = rwTopLeft.ToString("0.0"); RightTopDat.Text = rwTopRight.ToString("0.0"); LeftBottomDat.Text = rwBottomLeft.ToString("0.0"); RightBottomDat.Text = rwBottomRight.ToString("0.0"); WeightDat.Text = rwWeight.ToString("0.0"); CenterGravityX.Text = pointX.ToString("0.0"); CenterGravityY.Text = pointY.ToString("0.0"); Bitmap bufl = new Bitmap(DrawingPanel.Width, DrawingPanel.Height); using (Graphics g = Graphics.FromImage(bufl)) using (System.Drawing.Pen blackPen = new System.Drawing.Pen(System.Drawing.Color.Black)) using (System.Drawing.Pen redPen = new System.Drawing.Pen(System.Drawing.Color.Red)) { g.FillRectangle(Brushes.White, new Rectangle(0, 0, DrawingPanel.Width, DrawingPanel.Height)); g.DrawLine(blackPen, 0, DrawingPanel.Height / 2, DrawingPanel.Width, DrawingPanel.Height / 2); g.DrawLine(blackPen, DrawingPanel.Width / 2, 0, DrawingPanel.Width / 2, DrawingPanel.Height); int Xpos = DrawingPanel.Width / 2 + (int)(pointX * 10); if (InvertX.Checked) { Xpos = DrawingPanel.Width - Xpos; } int Ypos = DrawingPanel.Height / 2 + (int)(pointY * 10); if (InvertY.Checked) { Ypos = DrawingPanel.Height - Ypos; } System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(Xpos - 1, Ypos - 1, 2, 2); g.DrawRectangle(System.Drawing.Pens.Red, rectangle); g.DrawLine(redPen, Xpos - 5, Ypos, Xpos + 5, Ypos); g.DrawLine(redPen, Xpos, Ypos - 5, Xpos, Ypos + 5); DrawingPanel.CreateGraphics().DrawImageUnscaled(bufl, 0, 0); } }
public FormNotes() { InitializeComponent(); g = DrawingPanel.CreateGraphics(); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; p = new Pen(Color.Black); p.StartCap = p.EndCap = System.Drawing.Drawing2D.LineCap.Round; clearSketch(); }
private void ClearButton_Click(object sender, EventArgs e) { DrawingPanel.CreateGraphics().Clear(Color.White); Edges = new EList(); Vert = new EList(); //string a = "1\n2\n3\n4\n5"; //if (SFD.ShowDialog() == DialogResult.OK) // File.WriteAllText(SFD.FileName, a); }
private void DrawingPanel_MouseMove(object sender, MouseEventArgs e) { if (mouseDown) { _coordinates.SetXCoordinate(e.X.ToString()); _coordinates.SetYCoordinate(e.Y.ToString()); DrawingPanel.Invalidate(); } }
private void btn_newVillage_Click(object sender, EventArgs e) { DrawingPanel.Invalidate(); g.Clear(DrawingPanel.BackColor); vill = new Village(); Label_villName.Text = "Untitled"; selected_nation = ""; selected_component = ""; }
private void undoToolStripMenuItem_Click(object sender, EventArgs e) { if (objectsDrawn.Count != 0) { objectsDrawn.RemoveAt(objectsDrawn.Count - 1);//removes last object added to myDrawings } DrawingPanel.Invalidate(); //redraw accordingly }
private void ToolBox_SelectedIndexChanged(object sender, EventArgs e) { if (!inputStateManager.TryChangeTool((Tools)toolBox.SelectedIndex)) { toolBox.SelectedIndex = (int)inputStateManager.SelectedTool; return; } DrawingPanel.Refresh(); }
private void DrawingPanel_MouseWheel(object sender, MouseEventArgs e) { double x = Conv.XX(e.X), y = Conv.YY(e.Y); double changeCoeff = e.Delta > 0 ? 0.75 : 1.25; Conv.X1 = x - (x - Conv.X1) * changeCoeff; Conv.Y1 = y - (y - Conv.Y1) * changeCoeff; Conv.X2 = x + (Conv.X2 - x) * changeCoeff; Conv.Y2 = y + (Conv.Y2 - y) * changeCoeff; DrawingPanel.Invalidate(); }