Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7169739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:04:16+00:00 2026-05-28T15:04:16+00:00

I have own control and I need to resize runtime by dragging. To resize

  • 0

I have own control and I need to resize runtime by dragging. To resize bottom and right borders I use this:

protected override void OnMouseDown(MouseEventArgs e)
{
  SL = new System.Drawing.Point(Location.X + e.Location.X, Location.Y + e.Location.Y);
  SP = new System.Drawing.Point(Location.X, Location.Y);

  if (e.X <= m)
    _OnLeft = true;

  if (e.X >= Width - m)
    _OnRight = true;

  if (e.Y <= m)
    _OnTop = true;

  if (e.Y >= Height - m)
    _OnBottom = true;
}

protected override void OnMouseMove(MouseEventArgs e)
{
  // Change Width - right
  if (_OnRight && (!_OnTop && !_OnBottom))
  {
    if (e.X <= 1)
      return;
    Width = e.X;
    return;
  }

  // Change Height - bottom
  if (_OnBottom && (!_OnLeft && !_OnRight))
  {
    if (e.Y <= 1)
      return;
    Height = e.Y;
    return;
  }
}

All works fine. But I have problems with Top and Left resizing:

// Change Width - left
if (_OnLeft && (!_OnTop && !_OnBottom))
{
  // Problem part - I don't know condition to return
  if (Width + Left - e.X <= 1)
    return;
  Left += e.X - SL.X + SP.X;
  // How to get right width
  Width += Left - e.X;
  return;
}

// Change Height - top
if (_OnTop && (!_OnLeft && !_OnRight))
{
  // Problem part - I don't know condition to return
  if (Height + Top - e.Y <= 1)
    return;
  Top += e.Y - SL.Y + SP.Y;
  // How to get right height 
  Height += Top - e.Y;
  return;
}

Something like that. Have ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:04:17+00:00Added an answer on May 28, 2026 at 3:04 pm

    Pretty much the only way to cleanly allow .NET control resizing is to use P/Invoke. This exact code is not tested, but I have used this resizing method many times so it should work:

    First, the P/Invoke external declarations:

    private static class UnsafeNativeMethods
    {
        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
    }
    

    Next, call the P/Invoke functions to have the operating system handle the resize:

    protected override void OnMouseDown(MouseEventArgs e)
    {
        int msg = -1; //if (msg == -1) at the end of this, then the mousedown is not a drag.
    
        if (e.Y < 8)
        {
            msg = 12; //Top
            if (e.X < 25) msg = 13; //Top Left
            if (e.X > Width - 25) msg = 14; //Top Right
        }
        else if (e.X < 8)
        {
            msg = 10; //Left
            if (e.Y < 17) msg = 13;
            if (e.Y > Height - 17) msg = 16;
        }
        else if (e.Y > Height - 9)
        {
            msg = 15; //Bottom
            if (e.X < 25) msg = 16;
            if (e.X > Width - 25) msg = 17;
        }
        else if (e.X > Width - 9)
        {
            msg = 11; //Right
            if (e.Y < 17) msg = 14;
            if (e.Y > Height - 17) msg = 17;
        }
    
        if (msg != -1)
        {
            UnsafeNativeMethods.ReleaseCapture(); //Release current mouse capture
            UnsafeNativeMethods.SendMessage(Handle, 0xA1, new IntPtr(msg), IntPtr.Zero);
            //Tell the OS that you want to drag the window.
        }
    }
    

    Finally, override OnMouseMove to change the cursor based on where it is on the control. I’ll leave that part to you, because it’s almost the same code as the previous snippet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have need of a checked combobox control like this one --> DevExpress (I
I have my own control which derives from StackPanel. This control contains two other
Currently using System.Web.UI.WebControls.FileUpload wrapped in our own control. We have licenses for Telerik. I
I am trying to make my own user control and have almost finished it,
We have our own ORM we use here, and provide strongly typed wrappers for
I have my own asp.net cookie created like this: var authTicket = new FormsAuthenticationTicket(
I have my own control: public class newControl : Control { } There is
I have my own control derived from Windows.Forms.Control and I am checking the Parent.BackColor
I have a Silverlight control i need to convert to WPF (Yes, i know
I have My own Domain shakarganj.com.pk and I want to Use google Open ID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.