Changing the size of panels in c#

Searching the depths of the internet I came across a very interesting, extending a normal Forms.Panel ‘uo dynamically change its size. The class that provides this functionality, I found the msdn forum, here it is:

The class must be added to the project, compile. The new indicator should appear in the Toolbox.


using System;
using System.Drawing;
using  System.Windows.Forms;

public class SizeablePanel : Panel {
 private const int cGripSize = 20;
 private bool mDragging;
 private Point mDragPos;

 public SizeablePanel() {
 this.DoubleBuffered = true;
 this.SetStyle(ControlStyles.ResizeRedraw, true);
 this.BackColor =  Color.White;

 protected override void  OnPaint(PaintEventArgs e) {
 ControlPaint.DrawSizeGrip(e.Graphics,  this.BackColor,
 new Rectangle(this.ClientSize.Width -  cGripSize, this.ClientSize.Height - cGripSize, cGripSize, cGripSize));

 private bool IsOnGrip(Point pos) {
 return pos.X >= this.ClientSize.Width - cGripSize &&
 pos.Y >= this.ClientSize.Height - cGripSize;

 protected override void OnMouseDown(MouseEventArgs e) {
 mDragging  = IsOnGrip(e.Location);
 mDragPos = e.Location;

 protected override void  OnMouseUp(MouseEventArgs e) {
 mDragging = false;

 protected override void  OnMouseMove(MouseEventArgs e) {
 if (mDragging) {
 this.Size = new Size(this.Width + e.X - mDragPos.X,
 this.Height + e.Y - mDragPos.Y);
 mDragPos = e.Location;
 else if (IsOnGrip(e.Location)) this.Cursor = Cursors.SizeNWSE;
 else this.Cursor = Cursors.Default;

I would add only:


in OnMouseMove();.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • MySpace
  • PDF

Related Posts

  1. No comments yet.

  1. No trackbacks yet.



fotograf BydgoszczPhotosmart oryginalne tusze HP do drukarki zamienniki tonery HP Photosmart A617 Toner zamiennik tusz oryginalny do drukarek hp photosmart, sprawdź jak niskie są cenyurl