?
Solved

How do I resize windows form similar to photoshop logic?

Posted on 2010-01-03
6
Medium Priority
?
495 Views
Last Modified: 2012-05-08
While resizing c# windows form I would like to keep the form in its original size. the new size rectangle is drawed as transparent rectangle like in photoshop, see attached image. at resize end (mouse up) the form is resized into selected size
exm.JPG
0
Comment
Question by:rarchinio
  • 3
  • 2
6 Comments
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 26165256
i didn't understand, when u resize the form window u wish to keep the form in its original size???
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 26166869
Try this out....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private struct RECT
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
        }

        private bool Sizing = false;
        private RECT origRC;
        private Rectangle prevRC;
        private const int WM_ENTERSIZEMOVE = 0x231;
        private const int WM_SIZING = 0x214;
        private const int WM_EXITSIZEMOVE = 0x232;

        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            RECT RC;
            switch (m.Msg)
            {
                case WM_ENTERSIZEMOVE:
                    this.prevRC = this.Bounds;
                    this.origRC.Left = this.Bounds.Left;
                    this.origRC.Top = this.Bounds.Top;
                    this.origRC.Right = this.Bounds.Right;
                    this.origRC.Bottom = this.Bounds.Bottom;
                    break;

                case WM_SIZING:
                    if (this.Sizing)
                    {
                        ControlPaint.DrawReversibleFrame(this.prevRC, Color.Black, FrameStyle.Dashed);
                    }
                    else
                    {
                        this.Sizing = true;
                    }
                    RC = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));
                    this.prevRC = new Rectangle(RC.Left, RC.Top, (RC.Right - RC.Left + 1), (RC.Bottom - RC.Top + 1));
                    ControlPaint.DrawReversibleFrame(this.prevRC, Color.Black, FrameStyle.Dashed);
                    Marshal.StructureToPtr(this.origRC, m.LParam, true);
                    break;

                case WM_EXITSIZEMOVE:
                    if (this.Sizing)
                    {
                        this.Sizing = false;
                        ControlPaint.DrawReversibleFrame(this.prevRC, Color.Black, FrameStyle.Dashed);
                        this.Bounds = this.prevRC;
                    }
                    break;
            }

            base.WndProc(ref m);
        }

    }
}

Open in new window

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26166875
*My code assumed a STAND-ALONE form...if you're working with MdiChildren it will have to be re-worked a little...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:rarchinio
ID: 31672101
strange phenomenen is observed the frame is painted but it is not cleared at mouse location, few lines are left paited on the screen, how can it be overcomed?
0
 

Author Comment

by:rarchinio
ID: 26169228
strange phenomenen is observed, at the mouse location during slow resize the small part of the painted frame is not cleared and is still painted on the screen. see the attached file. How can I solve it? Thank you
Untitled.jpg
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26171399
Hmmm....I think it's the cursor causing the artifacts.

Try hiding it at drag start with Cursor.Hide() and then showing it at the end again with Cursor.Show().
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question