Kmot napisał(a)
Chciałbym aby przy jakimś komponencie, np txtbox po najechaniu na jego krawędź, pokazywała się ikonka z 2 strzałkami i istniała możliwość zmiany jego rozmiaru - np: dokładnie tak jak to jest w VS przy dodawaniu komponentów na formatkę.
Da radę to jakiś zrobić? :)
Inna sprawa - dla mnie teraz nie istotna ale skoro jesteśmy przy tym temacie... Jak zrobić żeby ładnie przesuwać kontrolkę z pomocą myszy. Myślałem, że to będzie proste bo wystarczy dodać w _MouseMove np coś takiego
if (e.Button == MouseButtons.Left)
{
textBox1.Left = e.X;
textBox1.Top = e.Y;
}
ale niedziała to poprawnie - miga i ucieka.
Wszystko ogranicza się do dodania zdarzenia ruchu myszka w zdarzeniu naciśnięcia klawiszy:
public Form1()
{
InitializeComponent();
this.textBox1.MouseDown += new MouseEventHandler(textBox1_MouseDown);
}
int[] pozycje = new int[2];
void textBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//zmiana rozmiarow
if (e.X > this.textBox1.Width-10 || e.Y > this.textBox1.Height -10)
{
pozycje = new int[] { e.X, e.Y };
this.textBox1.MouseMove += new MouseEventHandler(textBox1_MouseMove1);
this.textBox1.MouseUp += new MouseEventHandler(textBox1_MouseUp1);
}
//przesuniecie
else
{
pozycje = new int[] { e.X, e.Y };
this.textBox1.MouseMove += new MouseEventHandler(textBox1_MouseMove2);
this.textBox1.MouseUp += new MouseEventHandler(textBox1_MouseUp2);
}
}
}
void textBox1_MouseMove1(object sender, MouseEventArgs e)
{
this.textBox1.Width += (e.X-pozycje[0]);
this.textBox1.Height += (e.Y - pozycje[1]);
pozycje = new int[] { e.X, e.Y };
}
void textBox1_MouseMove2(object sender, MouseEventArgs e)
{
this.textBox1.Top += (e.X - pozycje[0]);
this.textBox1.Left += (e.Y - pozycje[1]);
pozycje = new int[] { e.X, e.Y };
}
void textBox1_MouseUp1(object sender, MouseEventArgs e)
{
this.textBox1.MouseMove -= new MouseEventHandler(textBox1_MouseMove1);
}
void textBox1_MouseUp2(object sender, MouseEventArgs e)
{
this.textBox1.MouseMove -= new MouseEventHandler(textBox1_MouseMove2);
}
Albo jakoś tak a co do migania to:
this.DoubleBuffered = true;