Click here to Skip to main content
15,900,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I learned custom shaped forms and buttons at

http://msdn.microsoft.com/en-us/library/aa289517(VS.71).aspx#vbtchshapedwindowsformscontrolsinvisualstudionetanchor1


there how to retain some properties like form dragging is explained but I wanted to know how to re-gain form resizing property which is not specified there.

How can be this property be re-gained and as we move mouse cursor to these custom form's border the mouse cursor should change as for resizing in normal forms. Moreover in taskbar if in normal forms we give mouse right-click it gives options in context menu like "close","restore","minimize" etc. this property also gets lost when we change "formborderstyle" property to "none". So how to also gain this property.

I wanted to know how some of these properties of Windows forms(in C#. Net) could be regained after setting the "formborderstlye" to "none".
Posted
Updated 30-Jul-10 5:35am
v2

So, I don't think you can get the right-click menu item to look exactly the same. The main reason is that I can't see a way to draw the contextMenuStrip below the top of the taskbar. But, what you can do is create your own ContextMenuStrip with the items you want. Then, you override the WndProc method and show the ContextMenuStrip. It looks like:

C#
private const int WMTaskbarRClick = 0x0313;

protected override void WndProc(ref Message m)
{
    switch (m.Msg)
    {
        case WMTaskbarRClick:
            contextMenuStrip1.Show(Cursor.Position);
            break;
        default:
            base.WndProc(ref m);
            break;
    }
}


Resizing the form is a bit trickier. You have to first decide on a region that you will be using to allow the resize. Once you've done that, you need to hook the mouse move and see if the cursor is in that region. If it is, then you change the cursor. Then, if the user mouses down while the cursor is changed, you start dragging.

It's easy for a rectangular form. I've done the following:
C#
private bool dragging = false;
private Point offset;
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    if (!dragging)
    {
        if (e.X < this.Width && e.X > this.Width - 10
            && e.Y < this.Height && e.Y > this.Height - 10)
        {
            offset = new Point(this.Width - e.X, this.Height - e.Y);
            this.Cursor = Cursors.SizeNWSE;
        }
        else
        {
            this.Cursor = Cursors.Default;
        }
    }
    else
    {
        this.Width = e.X + offset.X;
        this.Height = e.Y + offset.Y;
    }
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
    if (this.Cursor == Cursors.SizeNWSE)
        dragging = true;
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
    if (this.Cursor == Cursors.SizeNWSE)
        dragging = false;
}


I've basically defined a region to the bottom right where the user can mouse over and then resize it.
 
Share this answer
 
v2
Comments
Vikram_ 31-Jul-10 4:44am    
Reason for my vote of 5
This was the solution I was seeking for the problem or question I asked.
Vikram_ 31-Jul-10 4:47am    
Thanks for the help. I was expecting for the same solution as you provided here for my problem.
Hi Vikram

This is very simple, add the buttons for "Minimise" and Maximise
etc on the windowsform and on button click event of these buttons write as below

private void buttonMax_Click(object sender, EventArgs e)
{
  WindowState = FormWindowState.Maximised;
}

private void buttonMin_Click(object sender, EventArgs e)
{
  WindowState = FormWindowState.Minimized;
}
 
Share this answer
 
Comments
Vikram_ 31-Jul-10 4:54am    
Thanks for help. But sorry, I think you interpreted something different. Actually I knew this aspect. The thing in which I was having problem was the mouse events code for resizing forms. Well anyways this was also a helpful code for regaining titlebar buttons property. Thanks again.
Toli Cuturicu 31-Jul-10 8:13am    
Reason for my vote of 2
Correct, but the question was really about resize, not maximize or minimize.
William Winner 2-Aug-10 15:23pm    
Reason for my vote of 4
technically, the OP did ask how to regain the Maximize and Minimize Properties and technically, you did provide a solution to do that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900