0
Well, there are several ways to do it (Win API, using a separate rectangle, etc). Depending upon what you are really doing, you might be able to configure each control's anchor properties to achieve the desired effect as well. Possibly the easiest would be to respond to the controls mouse up, mouse down, and mouse move events. This is not perfect but it could get you started:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ResizableControls
{
public partial class Form1 : Form
{
bool rtbAllowDragging;
bool dgvAllowDragging;
public Form1()
{
InitializeComponent();
rtbAllowDragging = false;
dgvAllowDragging = false;
}
private void richTextBox1_MouseMove(object sender, MouseEventArgs e)
{
if(rtbAllowDragging)
{
richTextBox1.Height = richTextBox1.Top + e.Y;
richTextBox1.Width = richTextBox1.Left + e.X;
}
}
private void richTextBox1_MouseUp(object sender, MouseEventArgs e)
{
rtbAllowDragging = false;
richTextBox1.Cursor = Cursors.Default;
}
private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
{
rtbAllowDragging = true;
richTextBox1.Cursor = Cursors.SizeAll;
}
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
dgvAllowDragging = true;
dataGridView1.Cursor = Cursors.SizeAll;
}
private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
if (dgvAllowDragging)
{
dataGridView1.Height = dataGridView1.Top + e.Y;
dataGridView1.Width = dataGridView1.Left + e.X;
}
}
private void dataGridView1_MouseUp(object sender, MouseEventArgs e)
{
dgvAllowDragging = false;
dataGridView1.Cursor = Cursors.Default;
}
}
} 