private void panel1_MouseMove(object sender, MouseEventArgs e) { panel1.Focus(); Graphics g = panel1.CreateGraphics(); // Create graphics. g.InterpolationMode = InterpolationMode.NearestNeighbor; // Maintain pixelated quality while zooming. Pen pen = new Pen(Color.Black); // Set pen color to black. panel1.Refresh(); // Force the panel to repaint. panel1.SuspendLayout(); // Is a component selected? if (listView1.SelectedItems.Count > 0) { picb = new NNPictureBox(); // Get the selected item. ListViewItem listvi = listView1.SelectedItems[0]; Image compImg = imgl.Images[listvi.ImageIndex]; Rectangle rect = new Rectangle(); Image src = Rotate(compImg); // Grid pattern: // Get nearest multiple of 50 and set this to the X and Y coordinates. p.X = NearestMultiple(panel1.PointToClient(MousePosition).X, 50); p.Y = NearestMultiple(panel1.PointToClient(MousePosition).Y, 50); // Set rect location to a grid location. rect.Location = p; // Set image height and width to 50. rect.Width = 50; rect.Height = 50; // Display an image of the component that follows the cursor. g.DrawImage(src, rect); } panel1.ResumeLayout(); }
private void panel1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { // Is a component selected? if (listView1.SelectedItems.Count > 0) { picb = new NNPictureBox(); picb.IsInteractable = true; // Get the selected item. ListViewItem listvi = listView1.SelectedItems[0]; Image compImg = imgl.Images[listvi.ImageIndex]; Rectangle rect = new Rectangle(); Image src = Rotate(compImg); Graphics graphics = Graphics.FromImage(src); graphics.InterpolationMode = InterpolationMode.NearestNeighbor; graphics.PixelOffsetMode = PixelOffsetMode.None; // Get nearest multiple of 50 and set this to the X and Y coordinates. p.X = NearestMultiple(panel1.PointToClient(MousePosition).X, 50); p.Y = NearestMultiple(panel1.PointToClient(MousePosition).Y, 50); // If the component is a command block, show the set command // dialog and give the command block the command. if (listvi.Text == "Command Block") { CommandEnter ce = new CommandEnter(); if (ce.ShowDialog() == DialogResult.OK) { picb.ComponentTag = ce.Command; } } // Set rect location to a grid location. rect.Location = p; // Set image height and width to 50. rect.Width = 50; rect.Height = 50; // Block setup. picb.Parent = panel1; picb.Location = p; picb.Image = src; picb.Size = rect.Size; picb.ComponentName = listvi.Text; picb.SizeMode = PictureBoxSizeMode.StretchImage; picb.Visible = true; picb.RedoList = RedoList; picb.redoMItem = redoToolStripMenuItem; // Add component to the list. PictureBoxes.Add(picb); panel1.Controls.Add(picb); undoToolStripMenuItem.Enabled = true; // Tell the user there are unsaved changes. if (unsavedChanges == false) { Form1.ActiveForm.Text = ActiveForm.Text + "*"; unsavedChanges = true; } } // Place Wires } else if (e.Button == MouseButtons.Right) { picb = new NNPictureBox(); picb.IsInteractable = true; if (wireListView.SelectedItems.Count > 0) { // Get the selected item. ListViewItem listvi = wireListView.SelectedItems[0]; Image compImg = wireImageList.Images[listvi.ImageIndex]; Rectangle rect = new Rectangle(); Image src = Rotate(compImg); Graphics graphics = Graphics.FromImage(src); graphics.InterpolationMode = InterpolationMode.NearestNeighbor; graphics.PixelOffsetMode = PixelOffsetMode.None; // Get nearest multiple of 50 and set this to the X and Y coordinates. p.X = NearestMultiple(panel1.PointToClient(MousePosition).X, 50); p.Y = NearestMultiple(panel1.PointToClient(MousePosition).Y, 50); // Set rect location to a grid location. rect.Location = p; // Set image height and width to 50. rect.Width = 50; rect.Height = 50; // Block setup. picb.Parent = panel1; picb.Location = p; picb.ComponentName = "Wire"; picb.Image = src; picb.Size = rect.Size; picb.SizeMode = PictureBoxSizeMode.StretchImage; picb.Visible = true; picb.RedoList = RedoList; picb.redoMItem = redoToolStripMenuItem; // Add component to the list. PictureBoxes.Add(picb); panel1.Controls.Add(picb); undoToolStripMenuItem.Enabled = true; // Tell the user there are unsaved changes. if (unsavedChanges == false) { Form1.ActiveForm.Text = ActiveForm.Text + "*"; unsavedChanges = true; } } } }