views:

85

answers:

3

Hi,

In my application I have to resize forms and all its control on mouse drag effect and forms should have drop shadow effect the problem is that all my forms are custom one (with no boarder).

Thanks in advance

A: 

Without a border (or some control), how do you intend to resize? Figure that part out, then try this code in your form:

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);
    }
}

This code will resize your form as though the bottom right corner was used. Look up HT_BOTTOMRIGHT and other HT_ constants for different locations for resizing.

Matthew Ferreira
+1  A: 

i think u have to implement by yourself

  1. on mouse down start bind on mouse drag + change cursor to resize icon
  2. on mouse drag, just simply reduce your form size
  3. on mouse up unbind mouse drag event

the reason i suggest dynamic event binding so u can specified which control or area should have mouse down

888
Yeh I have Implement the re-size the same way few days ago. But I think I should select your answer because you were the first one to post here.
Ravi shankar
+1  A: 

I'm not sure about the drop shadow effect, but you should be able to resize a form by placing a button in the bottom right corner with some appropriate icon. When the user clicks and drags this button, it resizes the form. Here's some example code:

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;
    }
}
Don Kirkby
One Up for been more precise.
Ravi shankar