Moving Pictureboxes from left to right - c#

I have 4 pictureBoxes. I need they move until hit right side and then move to left side and again. But after 1st picturebox hit left side other move closer to him. How fix it ??
link on video with problem
int changePositionX;
bool change = true;
private void timer1_Tick(object sender, EventArgs e)
{
foreach (Control x in this.Controls)
{
if (x is PictureBox && x.Tag != null && x.Tag.ToString() == "enemy")
{
if (x.Location.X < 750 && change == true)
{
changePositionX = x.Location.X + 50;
x.Location = new Point(changePositionX, x.Location.Y);
}
else
{
change = false;
}
if(x.Location.X >= 100 && change == false)
{
changePositionX = x.Location.X - 50;
x.Location = new Point(changePositionX, x.Location.Y);
}
else
{
change = true;
}
}
}
}

Try it like this instead:
private int jumpDistance = 50;
private bool goingRight = true;
private List<PictureBox> PBs = new List<PictureBox>();
private void Form1_Load(object sender, EventArgs e)
{
foreach (PictureBox pb in this.Controls.OfType<PictureBox>())
{
if (pb.Tag != null && pb.Tag.ToString() == "enemy")
{
PBs.Add(pb);
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (goingRight)
{
if (PBs.Any(pb => pb.Location.X >= 750))
{
goingRight = !goingRight;
}
}
else
{
if (PBs.Any(pb => pb.Location.X < 100))
{
goingRight = !goingRight; ;
}
}
foreach (PictureBox pb in PBs)
{
if (goingRight)
{
pb.Location = new Point(pb.Location.X + jumpDistance, pb.Location.Y);
}
else // going left
{
pb.Location = new Point(pb.Location.X - jumpDistance, pb.Location.Y);
}
}
}
Here's my code doing its thing with four PictureBoxes:

Related

How can i keep adding images to pictureBox1 when cropping and adding items to the listBox1 if the flag saveRectangles is false?

This is a link to the winforms project from my onedrive:
https://1drv.ms/u/s!AmVw2eqP6FhB4h01pNXIMlqdZJk_?e=wSGaRx
using Newtonsoft.Json;
using Ookii.Dialogs.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
namespace Image_Crop
{
public partial class Form1 : Form
{
Rectangle rect;
int pixelsCounter = 0;
Color SelectedColor = Color.LightGreen;
List<DrawingRectangle> DrawingRects = new List<DrawingRectangle>();
Bitmap rectImage;
int saveRectanglesCounter = 1;
bool drawBorder = true;
bool clearRectangles = true;
bool saveRectangles = true;
//bool drawnNewRectangle = false; // To think how to work with this flag bool variable
// where to use it how and how to solce this problem !!!!!
string rectangleName;
Dictionary<string, string> FileList = new Dictionary<string, string>();
string selectedPath;
int x, y;
private bool crop = false;
public Form1()
{
InitializeComponent();
textBox1.Text = Properties.Settings.Default.ImageToCropFolder;
textBox2.Text = Properties.Settings.Default.CroppedImagesFolder;
selectedPath = textBox2.Text;
if (textBox1.Text != "")
{
Bitmap bmp = new Bitmap(Image.FromFile(textBox1.Text),
pictureBox2.Width, pictureBox2.Height);
pictureBox2.Image = bmp;
}
checkBoxDrawBorder.Checked = true;
checkBoxClearRectangles.Checked = true;
checkBoxSaveRectangles.Checked = true;
if (selectedPath != "" && selectedPath != null)
{
if (System.IO.File.Exists(Path.Combine(selectedPath, "rectangles.txt")))
{
string g = System.IO.File.ReadAllText(Path.Combine(selectedPath, "rectangles.txt"));
g = g.Remove(0, 32);
FileList = JsonConvert.DeserializeObject<Dictionary<string, string>>(g);
listBox1.DataSource = FileList.Keys.ToList();
label2.Text = listBox1.Items.Count.ToString();
listBox1.SelectedIndex = listBox1.Items.Count - 1;
}
else
{
label2.Text = "0";
}
}
else
{
label2.Text = "0";
}
if ((selectedPath != "" && selectedPath != null) && textBox1.Text != "")
{
crop = true;
}
else
{
crop = false;
}
}
public class DrawingRectangle
{
public Rectangle Rect => new Rectangle(Location, Size);
public Size Size { get; set; }
public Point Location { get; set; }
public Control Owner { get; set; }
public Point StartPosition { get; set; }
public Color DrawingcColor { get; set; } = Color.LightGreen;
public float PenSize { get; set; } = 3f;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left || crop == false) return;
x = 0;
y = 0;
if (pictureBox2.Image != null && selectedPath != null)
{
if ((x >= 0 && x <= pictureBox2.Image.Size.Width) && (y >= 0 && y <= pictureBox2.Image.Size.Height))
{
DrawingRects.Add(new DrawingRectangle()
{
Location = e.Location,
Size = Size.Empty,
StartPosition = e.Location,
Owner = (Control)sender,
DrawingcColor = SelectedColor
});
}
}
}
private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
{
int X = e.X;
int Y = e.Y;
if (e.Button != MouseButtons.Left || crop == false) return;
if ((X >= 0 && X <= pictureBox2.Width) && (Y >= 0 && Y <= pictureBox2.Height))
{
if (pictureBox2.Image != null && selectedPath != null && DrawingRects.Count > 0)
{
if ((x >= 0 && x <= pictureBox2.Image.Size.Width) && (y >= 0 && y <= pictureBox2.Image.Size.Height))
{
x = e.X;
y = e.Y;
var dr = DrawingRects[DrawingRects.Count - 1];
if (e.Y < dr.StartPosition.Y) { dr.Location = new Point(dr.Rect.Location.X, e.Y); }
if (e.X < dr.StartPosition.X) { dr.Location = new Point(e.X, dr.Rect.Location.Y); }
dr.Size = new Size(Math.Abs(dr.StartPosition.X - e.X), Math.Abs(dr.StartPosition.Y - e.Y));
pictureBox2.Invalidate();
}
}
}
}
int count = 0;
private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left || crop == false) return;
if (DrawingRects.Count > 0 && pictureBox2.Image != null && selectedPath != "")
{
if ((x >= 0 && x <= pictureBox2.Image.Size.Width) && (y >= 0 && y <= pictureBox2.Image.Size.Height))
{
var dr = DrawingRects.Last();
if (dr.Rect.Width > 0 && dr.Rect.Height > 0)
{
rectImage = cropAtRect((Bitmap)pictureBox2.Image, dr.Rect);
if (saveRectangles)
{
count++;
rectangleName = GetNextName(Path.Combine(selectedPath, "Rectangle"), ".bmp");
FileList.Add($"{dr.Location}, {dr.Size}", rectangleName);
string json = JsonConvert.SerializeObject(
FileList,
Formatting.Indented
);
using (StreamWriter sw = new StreamWriter(Path.Combine(selectedPath, "rectangles.txt"), false))
{
sw.WriteLine("Total number of rectangles: " + count + Environment.NewLine);
sw.Write(json);
sw.Close();
}
rectImage.Save(rectangleName);
saveRectanglesCounter++;
}
pixelsCounter = rect.Width * rect.Height;
pictureBox1.Invalidate();
listBox1.DataSource = FileList.Keys.ToList();
listBox1.SelectedIndex = listBox1.Items.Count - 1;
pictureBox2.Focus();
Graphics g = Graphics.FromImage(this.pictureBox1.Image);
g.Clear(this.pictureBox1.BackColor);
}
}
else
{
if (clearRectangles)
{
DrawingRects.Clear();
pictureBox2.Invalidate();
}
x = 0;
y = 0;
}
}
}
string GetNextName(string baseName, string extension)
{
int counter = 1;
string nextName = baseName + counter + extension;
while (System.IO.File.Exists(nextName))
{
counter++;
nextName = baseName + counter + extension;
}
return nextName;
}
private void pictureBox2_Paint(object sender, PaintEventArgs e)
{
if (drawBorder)
{
ControlPaint.DrawBorder(e.Graphics, pictureBox2.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);
}
if (pictureBox2.Image != null && selectedPath != null && DrawingRects.Count > 0)
{
DrawShapes(e.Graphics);
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (drawBorder)
{
ControlPaint.DrawBorder(e.Graphics, pictureBox1.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);
}
if (rectImage != null && DrawingRects.Count > 0)
{
var dr = DrawingRects.Last();
e.Graphics.DrawImage(rectImage, dr.Rect);
if (clearRectangles)
{
DrawingRects.Clear();
pictureBox2.Invalidate();
}
}
}
private void DrawShapes(Graphics g)
{
if (DrawingRects.Count == 0) return;
g.SmoothingMode = SmoothingMode.AntiAlias;
foreach (var dr in DrawingRects)
{
if (dr.Rect.Width > 0 && dr.Rect.Height > 0)
{
using (Pen pen = new Pen(dr.DrawingcColor, dr.PenSize))
{
g.DrawRectangle(pen, dr.Rect);
};
}
}
}
public Bitmap cropAtRect(Bitmap b, Rectangle r)
{
Bitmap nb = new Bitmap(r.Width, r.Height);
using (Graphics g = Graphics.FromImage(nb))
{
g.DrawImage(b, -r.X, -r.Y);
return nb;
}
}
private void checkBoxDrawBorder_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxDrawBorder.Checked)
{
drawBorder = true;
}
else
{
drawBorder = false;
}
pictureBox1.Invalidate();
pictureBox2.Invalidate();
}
private void checkBoxClearRectangles_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxClearRectangles.Checked)
{
clearRectangles = true;
}
else
{
clearRectangles = false;
}
pictureBox2.Invalidate();
}
private void checkBoxSaveRectangles_CheckedChanged(object sender, EventArgs e)
{
if(checkBoxSaveRectangles.Checked)
{
saveRectangles = true;
}
else
{
saveRectangles = false;
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var item = ((ListBox)sender).SelectedItem;
var val = FileList[(string)item];
pictureBox1.Image = System.Drawing.Image.FromFile(val);
}
private void button1_Click(object sender, EventArgs e)
{
VistaOpenFileDialog dialog = new VistaOpenFileDialog();
{
dialog.Filter = "Images (*.jpg, *.bmp, *.gif)|*.jpg;*.bmp;*.gif";
};
if (dialog.ShowDialog() == DialogResult.OK)
{
textBox1.Text = dialog.FileName;
Properties.Settings.Default.ImageToCropFolder = dialog.FileName;
Properties.Settings.Default.Save();
Bitmap bmp = new Bitmap(Image.FromFile(dialog.FileName),
pictureBox2.Width, pictureBox2.Height);
pictureBox2.Image = bmp;
if(textBox1.Text != "" && textBox2.Text != "")
{
crop = true;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
textBox2.Text = dialog.SelectedPath;
selectedPath = dialog.SelectedPath;
Properties.Settings.Default.CroppedImagesFolder = selectedPath;
Properties.Settings.Default.Save();
if (textBox1.Text != "" && textBox2.Text != "")
{
crop = true;
}
}
}
}
}
The problem is in the mouse up event i can't find the logic with the saving flag saveRectangles.
this is the saving part in the mouse up
if (saveRectangles)
{
count++;
rectangleName = GetNextName(Path.Combine(selectedPath, "Rectangle"), ".bmp");
FileList.Add($"{dr.Location}, {dr.Size}", rectangleName);
string json = JsonConvert.SerializeObject(
FileList,
Formatting.Indented
);
using (StreamWriter sw = new StreamWriter(Path.Combine(selectedPath, "rectangles.txt"), false))
{
sw.WriteLine("Total number of rectangles: " + count + Environment.NewLine);
sw.Write(json);
sw.Close();
}
rectImage.Save(rectangleName);
saveRectanglesCounter++;
}
if the checkBox checkBoxSaveRectangles is not checked when running the application and the folder in textBox1 is empty there are no saved images yet on the hard disk then it will throw exception at the line 201 in the MouseUp event :
Graphics g = Graphics.FromImage(this.pictureBox1.Image);
because the image in pictureBox1 is null.
but in that case i still want it to crop images and add the images information as items to the listBox just not to save it to the hard disk.
i think that rectImage variable is also used in the pictureBox1 paint event.
anyway the goal is to be able to keep cropping even if the saving checkbox not checked and the there are no saved images in the cropped images folder.

C# Windows Form snake

I have this simple snake game, my problem is that the tails wont add when it reaches three tails.
namespace Snake
{
public partial class Form1 : Form
{
bool left = false, right = false;
bool top = false, down = false;
PictureBox pic = new PictureBox();
List<PictureBox> tails = new List<PictureBox>();
int score = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (((e.KeyChar.ToString() == "a") || (e.KeyChar.ToString() == "A"))&&(right == false))
{
right = false;
top = false;
down = false;
left = true;
}
else if (((e.KeyChar.ToString() == "d") || (e.KeyChar.ToString() == "D"))&& (left == false))
{
top = false;
down = false;
left = false;
right = true;
}
else if (((e.KeyChar.ToString() == "w") || (e.KeyChar.ToString() == "W"))&& (down == false))
{
down = false;
left = false;
right = false;
top = true;
}
else if (((e.KeyChar.ToString() == "s") || (e.KeyChar.ToString() == "S"))&& (top == false))
{
top = false;
left = false;
right = false;
down = true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
//ticks every 1 sec
if (pic.Location == head.Location)
{
score++;
spawnFood();
tails.Add(addTails());
}
sortLocation();
if (right == true)
{
int r = head.Location.X + head.Height;
head.Location = new Point(r, head.Location.Y);
}
else if(left == true)
{
int l = head.Location.X - head.Height;
head.Location = new Point(l, head.Location.Y);
}
else if (top == true)
{
int t = head.Location.Y - head.Height;
head.Location = new Point(head.Location.X, t);
}
else if (down == true)
{
int d = head.Location.Y + head.Height;
head.Location = new Point(head.Location.X,d);
}
txtScore.Text = score.ToString();
}
private void sortLocation()
{
if (tails.Count == 0)
{
}
else
{
for (int i = 1; i < tails.Count; i++)
{
tails[i].Location = tails[i-1].Location;
}
tails[0].Location = head.Location;
}
}
private PictureBox addTails()
{
PictureBox tail = new PictureBox();
tail.Name = "tail" + score.ToString();
tail.BackColor = Color.Black;
tail.Width = 10;
tail.Height = 10;
this.Controls.Add(tail);
return tail;
}
private void spawnFood()
{
Random rnd = new Random();
int rndLocationX = rnd.Next(10, 50);
int rndLocationY = rnd.Next(10, 50);
pic.BackColor = Color.Red;
pic.Height = 10;
pic.Width = 10;
this.Controls.Add(pic);
if (rndLocationX >= 500)
{
rndLocationX -= 10;
}
if (rndLocationY >= 500)
{
rndLocationY -= 10;
}
pic.Location = new Point(rndLocationX*10,rndLocationY*10);
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
spawnFood();
}
}
}
for (int i = 1; i < tails.Count; i++)
{
tails[i].Location = tails[i+1].Location;
}
tails[0].Location = head.Location;
Are your tails there just stacked so to speak? That's another thought I might be thinking. I changed the tails[i-1] to tails [i+1]. Check if that does the trick.

Eraser on inkcanvas in wpf

private void inkcanvas_StrokeErased(object sender, RoutedEventArgs e)
{
var erasedstrokes = (sender as InkCanvas).Strokes;
aftererasedstrokecollection = erasedstrokes;
foreach (var item in aftererasedstrokecollection)
{
removedstrokes.Add(item);
}
}
private void inkcanvas_StrokeErasing(object sender InkCanvasStrokeErasingEventArgs e)
{
var beforeerased = (sender as InkCanvas).Strokes;
beforeerasedstrokecollection = beforeerased;
foreach (var item in beforeerasedstrokecollection)
{
unremovedstrokes.Add(item);
}
}
private void btnUndo_Click(object sender, RoutedEventArgs e)
{
if (DrawingTool == "Eraser" || DrawingTool == "Delete")
{
int length = removedstrokes.Count;
for (int i = 0; i < length; i++)
{
estroke = removedstrokes[i];
inkcanvas.Strokes.Remove(estroke);
}
for (int i = 0; i < unremovedstrokes.Count; i++)
{
estroke = unremovedstrokes[i];
inkcanvas.Strokes.Add(estroke);
}
}
else
{
if (inkcanvas.Strokes.Count > 0)
{
int i = inkcanvas.Strokes.Count;
inkcanvas.Strokes.RemoveAt(i - 1);
}
}
removedstrokes.Clear();
DrawingTool = "UnDo";
HighlightSelectedButton(sender);
IsDrawing = false;
inkcanvas.EditingMode = InkCanvasEditingMode.None;
}
I want to draw again erased strokes on undo click in WPF. through above code i do this for single stroke but i want to do same for multiple strokes.
please suggest any idea.
how i get only erased point by erasedbypoint method of inkcanvas

Control flicker while dragging in run time

Stack Overflow users. In a C# VS 2010 Windows Form project I have a problem regarding control flicker when dragging a user created control around on a tab page during run time. I used the following code:
private void control_MouseMove(object sender, MouseEventArgs e)
{
if (isDragged)
{
Point newPoint = ((Control)sender).PointToScreen(new Point(e.X,
e.Y));
newPoint.Offset(ptOffset);
((Control)sender).Location = newPoint;
((Control)sender).Refresh();
}
}
private void control_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDragged = true;
Point ptStartPosition = ((Control)sender).PointToScreen(new
Point(e.X, e.Y));
ptOffset = new Point();
ptOffset.X = ((Control)sender).Location.X - ptStartPosition.X;
ptOffset.Y = ((Control)sender).Location.Y - ptStartPosition.Y;
}
else
{
isDragged = false;
}
}
private void control_MouseUp(object sender, MouseEventArgs e)
{
((Control)sender).Refresh();
isDragged = false;
}
private void createButton_PB_Click(object sender, EventArgs e)
{
int ctrlExists = 0;
string btnName = btnName_TB.Text;
foreach (Button button in tabControl1.SelectedTab.Controls)
{
if (button.Text == btnName)
{
ctrlExists = 1;
}
}
if (btnName_TB.Text != "" && ctrlExists == 0)
{
Button newButton = new Button();
newButton.Name = btnName.Replace(" ", String.Empty);
newButton.Name += "u";
newButton.Text = btnName;
tabControl1.SelectedTab.Controls.Add(newButton);
newButton.Left = 10;
newButton.Top = 420;
lastBtnClicked = newButton;
}
SetupClickEvents(tabControl1.SelectedTab);
}
So, the problem is that I can add a button and drag it around in run time. But, when I add another Button and drag it around...after I've done that, and go back to trying to drag the first button, that button flickers and acts as if it is trying to move all over the place. Sometimes it disappears. I feel like this has something to do with the fact that the controls are inside a tab page. Perhaps I am not properly calculating the "newPoint" variable. Any ideas guys?
Ok, so I found a few fundamental flaws related to the button creation and the events that were being added at the time of creation. I made some considerable changes and the issue seems to have gone away. Following is the updated code.
private void control_MouseMove(object sender, MouseEventArgs e)
{
if (isDragged)
{
Point newPoint = ((Control)sender).PointToScreen(new Point(e.X,
e.Y));
newPoint.Offset(ptOffset);
((Control)sender).Location = newPoint;
((Control)sender).Refresh();
}
}
private void control_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && checkBox1.Checked)
{
isDragged = true;
((Control)sender).MouseMove += new
MouseEventHandler(control_MouseMove);
Point ptStartPosition = ((Control)sender).PointToScreen(new
Point(e.X, e.Y));
ptOffset = new Point();
ptOffset.X = ((Control)sender).Location.X - ptStartPosition.X;
ptOffset.Y = ((Control)sender).Location.Y - ptStartPosition.Y;
}
else
{
isDragged = false;
}
}
private void control_MouseUp(object sender, MouseEventArgs e)
{
((Control)sender).MouseMove -= control_MouseMove;
((Control)sender).Refresh();
isDragged = false;
}
private void SetupClickEvents(Control control)
{
control.Click += new EventHandler(StoreLastClick);
control.MouseDown += new MouseEventHandler(control_MouseDown);
//control.MouseMove += new MouseEventHandler(control_MouseMove);
control.MouseUp += new MouseEventHandler(control_MouseUp);
}
private void createButton_PB_Click(object sender, EventArgs e)
{
ctrlExists = 0;
string btnName = btnName_TB.Text;
foreach (Button button in tabControl1.SelectedTab.Controls)
{
if (button.Name == btnName)
{
ctrlExists = 1;
}
}
if (btnName_TB.Text != "" && ctrlExists == 0)
{
Button newButton = new Button();
newButton.Name = btnName.Replace(" ", String.Empty);
newButton.Text = btnName;
tabControl1.SelectedTab.Controls.Add(newButton);
newButton.Left = 10;
newButton.Top = 420;
SetupClickEvents(newButton);
}
}
private void deleteButton_PB_Click(object sender, EventArgs e)
{
ctrlExists = 0;
if (lastCtrlClicked != null)
{
string btnName = lastCtrlClicked.Name;
foreach (Button button in tabControl1.SelectedTab.Controls)
{
if (button.Name == btnName)
{
ctrlExists = 1;
}
}
}
if (ctrlExists == 1 && lastCtrlClicked != null)
{
tabControl1.SelectedTab.Controls.Remove(lastCtrlClicked);
lastCtrlClicked.Dispose();
ctrlExists = 0;
}
lastCtrlClicked = null;
}

How to identify dynamically created panels in c#?

I am doing a Windows Form Application in c# in which I create a panel for every click i do in "Panel_Inside".
But my problem is when I have to select one especific panel. I do not know how can I identify each panel.
Also I'm having problems when Dragging and Dropping for the same reason.
public void Coloco_Figura(string figura, int Punto_X, int Punto_Y)
{
panel_foto = new Panel();
panel_foto.BackColor = Color.Transparent; //saco fondo
panel_foto.BackgroundImage = Image.FromFile(figura); //asigno imagen al panel
panel_foto.BackgroundImageLayout = ImageLayout.Stretch;
panel_foto.Size = new Size(45, 45);
panel_foto.Location = new Point(Punto_X - 10, Punto_Y - 10);
panel_foto.BringToFront();
panel1.SendToBack();
panel_inside.Controls.Add(panel_foto);
dame_x = Punto_X;
this.panel_foto.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDown);
this.panel_foto.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUp);
this.panel_foto.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MouseMove);
}
here are mouse events
private void MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
# region Borrar Notas
if (Estado_Borro == true)
{
foreach (Panel p in panel_inside.Controls)
{
if (p is Panel)
{
panel_inside.Controls.Remove(p);
if (panel_inside.Controls.Count == 0)
{
listanotas.Clear();
}
else
{
for (int i = 0; i < listanotas.Count; i++)
{
Notas nota = listanotas[i];
if (nota.posX == dame_x)
{
listanotas.Remove(nota);
}
}
}
}
}
Estado_Borro = false;
}
if (e.Button == MouseButtons.Left)
{
drag = true;
x = e.X;
y = e.Y;
}
}
public void MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
drag = false;
}
public void MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (drag)
{
this.panel_foto.Location = new Point(Cursor.Position.X-this.Left, Cursor.Position.Y-this.Top);
}
To identify each panel, first you must set the Name or Tag property:
panel_foto.Name = "panel_foto1";
Then in your event handler,do something like this:
Panel p=(Panel)sender;
if (p.Name == "panel_foto1")
{
//Do your staff
}

Categories