otóż mam taki problem gdyż mam pictureBoxa z tłem białym (imituje mi kartke a4) teraz tworze dynamicznie labele picture boxy i układam na nim... Mam oprogramowane przemieszczanie tych elementów lecz gdy robie przemieszczenie to strzasznie migają (pomimą DoubleBuffered na formie) i pojawiają się tak jakby 2 kontrolki te same (po przestaniu przesuwania znika jedna)
Oto kod
private Point Pnl_Srodek(int Width,int Height)
{
int pnl_wysokosc = pb_roboczy.Height;
int pnl_szerokosc = pb_roboczy.Width;
Point pnl_srodek = new Point((pnl_szerokosc-Width) / 2, (pnl_wysokosc-Height) / 2);
return pnl_srodek;
}
private void btn_pole_tekstowe_Click(object sender, EventArgs e)
{
Label label = new Label();
label.MouseDown += new MouseEventHandler(label_MouseDown);
label.MouseUp += new MouseEventHandler(label_MouseUp);
label.MouseMove += new MouseEventHandler(label_MouseMove);
label.MouseDoubleClick += new MouseEventHandler(label_MouseDoubleClick);
label.AutoSize = true;
label.Name = "etykieta_" + Licznik_labeli.ToString();
label.Text = "Przykładowy tekst";
label.Location = Pnl_Srodek(label.Width, label.Height);
Licznik_labeli++;
pb_roboczy.Controls.Add(label);
}
void label_MouseDoubleClick(object sender, MouseEventArgs e)
{
Control ctrl = (Control)sender;
if (ctrl is Label)
{
Licznik_labeli--;
}
else if (ctrl is PictureBox)
{
Licznik_Picture_Box--;
}
ctrl.Dispose();
}
private Point ostatni = Point.Empty;
private Point aktualnie = Point.Empty;
private void label_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
pb_roboczy.Invalidate(true);
pb_roboczy.Update();
Control ctrl = (Control)sender;
aktualnie.X = e.X - ostatni.X;
aktualnie.Y = e.Y-ostatni.Y;
if (aktualnie.X < 5)
aktualnie.X = 5;
if (aktualnie.Y < 5)
aktualnie.Y = 5;
if (aktualnie.X > pb_roboczy.Width - ctrl.Width - 5)
aktualnie.X = pb_roboczy.Width - ctrl.Width - 5;
if (aktualnie.Y > pb_roboczy.Height - ctrl.Width - 5)
aktualnie.Y = pb_roboczy.Height - ctrl.Height - 5;
ctrl.Location = aktualnie;
ctrl.Invalidate();
pb_roboczy.Invalidate(true);
ctrl.Update();
}
}
private void label_MouseUp(object sender, MouseEventArgs e)
{
Control ctrl = (Control)sender;
ctrl.Font = new Font("Microsoft Sans Serif",9);
ctrl.ForeColor = Color.Black;
ostatni = Point.Empty;
aktualnie = Point.Empty;
}
private void label_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Control ctrl = (Control)sender;
ctrl.Font = new Font("Arial", 10, FontStyle.Bold);
ctrl.ForeColor = Color.FromArgb(60, 236, 40);
ostatni.X = e.X;
ostatni.Y = e.Y;
ctrl.Invalidate();
ctrl.Update();
}
}
Proszę o pilną pomoc