2010-10-04 10 views

Odpowiedz

2

myślę, że u trzeba zaimplementować sam

  1. na myszy uruchomić BIND przeciągnij mysz + Zmiana kursora, aby zmienić rozmiar ikon
  2. na przeciągnij myszą, po prostu zmniejszyć rozmiar formularz
  3. na myszy up unbind mysz wydarzenie przeciągnij

powodem proponuję dynamiczne zdarzenie wiązania więc u można określić, które kontrolowania lub obszar powinien mieć myszką w dół

+0

Yeh Wprowadziłem zmianę rozmiaru w ten sam sposób kilka dni temu. Ale myślę, że powinienem wybrać twoją odpowiedź, ponieważ byłeś pierwszym, który napisał tutaj. –

0

Bez granic (lub Control), w jaki sposób zamierza Pan zmienić? Dowiedzieć, że część na zewnątrz, a następnie spróbuj tego kodu w postaci:

public class CustomForm : Form 
{ 
    private const int WmNcLButtonDown = 0xA1; 
    private const int HtBottomRight = 17; 

    [DllImport("user32.dll")] 
    private static extern int ReleaseCapture(); 

    [DllImport("user32.dll")] 
    private static extern int SendMessage(IntPtr hwnd, int msg, int wparam, int lparam); 

    // elsewhere 
    void ResizeForm() 
    { 
     ReleaseCapture(); 
     SendMessage(this.Handle, WmNcLButtonDown, HtBottomRight, 0); 
    } 
} 

Ten kod rozmiaru formularza jakby prawy dolny róg był używany. Wyszukaj HT_BOTTOMRIGHT i inne stałe HT_ dla różnych lokalizacji do zmiany rozmiaru.

1

Nie jestem pewien co do efektu cienia, ale powinieneś mieć możliwość zmiany rozmiaru formularza poprzez umieszczenie przycisku w prawym dolnym rogu z odpowiednią ikoną. Kiedy użytkownik kliknie i przeciągnie ten przycisk, zmienia rozmiar formularza. Oto przykładowy kod:

public partial class Form1 : Form 
{ 
    private int bottomBorder; 
    private int rightBorder; 
    private Point mouseStart; 
    private bool isResizing = false; 

    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_MouseMove(object sender, MouseEventArgs e) 
    { 
     if (isResizing) 
     { 
      var newLocation = button1.Location; 
      newLocation.Offset(
       e.X - mouseStart.X, 
       e.Y - mouseStart.Y); 
      button1.Location = newLocation; 
      this.Height = button1.Bottom + bottomBorder; 
      this.Width = button1.Right + rightBorder; 
      button1.Refresh(); 
     } 

    } 

    private void button1_MouseDown(object sender, MouseEventArgs e) 
    { 
     isResizing = true; 
     mouseStart = e.Location; 
    } 

    private void button1_MouseUp(object sender, MouseEventArgs e) 
    { 
     isResizing = false; 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     bottomBorder = this.Height - button1.Bottom; 
     rightBorder = this.Width - button1.Right; 
    } 
} 
+0

One Up był dokładniejszy. –

0

Użyłem rozwiązań Don Kirkby'ego i Matthew Ferreiry i stworzyłem własne rozwiązanie łączące te dwa. Dodałem StatusStrip o nazwie "resizeHandle", zrobiłem jego rozmiar 20x20 pikseli i słuchałem jego wydarzeń.

public class CustomForm : Form 
{ 
private const int WmNcLButtonDown = 0xA1; 
private const int HtBottomRight = 17; 
private const int wmNcLButtonUp = 0xA2; 
private bool isResizing = false; 

[DllImport("user32.dll")] 
private static extern int ReleaseCapture(); 

[DllImport("user32.dll")] 
private static extern int SendMessage(IntPtr hwnd, int msg, int wparam, int lparam); 

private void resizeHandle_MouseDown(object sender, MouseEventArgs e) 
{ 
    isResizing = true; 
} 

private void resizeHandle_MouseMove(object sender, MouseEventArgs e) 
{ 
    if (isResizing) 
    { 
     // Check if we have released the Left mouse button 
     isResizing = (e.Button == MouseButtons.Left); 
     ReleaseCapture(); 
     if (isResizing) 
     { 
      SendMessage(Handle, wmNcLButtonDown, HtBottomRight, 0); 
     } 
     else 
     { 
      // Left Mouse button was released, end resizing. 
      SendMessage(Handle, wmNcLButtonUp, HtBottomRight, 0); 
     } 
    } 
} 
Powiązane problemy