Click here to Skip to main content
Click here to Skip to main content

Tagged as

Custom Windows Panel

, 15 Mar 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Every control in this panel can change the size and move on the panel


I've downloaded some articles to use in my project for resizing and moving every control at runtime, but those aren't more efficient in my conditions. So I decided to make a custom panel to do that. It's useful for some projects such as report generator and more.

Using the Code

Canvas class is inherited from Panel control and in the OnControlAdded method of the panel, some events are used to handle moving controls.

Canvas has defined Tracker class to handle resizing the control on the panel.

Just drag and drop the custom panel (named Canvas) on the form and put some controls to test it.

public class Canvas : Panel
protected override void OnControlAdded(System.Windows.Forms.ControlEventArgs e)
if (e.Control is Tracker)

e.Control.MouseEnter += new EventHandler(Control_MouseEnter);
e.Control.MouseLeave += new EventHandler(Control_MouseLeave);
e.Control.MouseDown += new MouseEventHandler(Control_MouseDown);
e.Control.MouseMove += new MouseEventHandler(Control_MouseMove);
e.Control.MouseUp += new MouseEventHandler(Control_MouseUp);

e.Control.LocationChanged += new EventHandler(Control_LocationChanged);

e.Control.HandleDestroyed += new EventHandler(Control_HandleDestroyed);


  • 29th May, 2009: Initial post
  • 15th Mar, 2010: Updated source code


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


About the Author

Alireza Soleimani
Software Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
No Biography provided

Comments and Discussions

SuggestionDoesn't work when scrolled off the screen PinmemberMachineGun2-Nov-11 15:16 
GeneralRe: Doesn't work when scrolled off the screen Pinmemberchrisbray2-Nov-11 20:59 
GeneralRe: Doesn't work when scrolled off the screen PinmemberMachineGun4-Nov-11 6:00 
GeneralRe: Doesn't work when scrolled off the screen Pinmemberchrisbray4-Nov-11 6:18 
GeneralRe: Doesn't work when scrolled off the screen PinmemberMachineGun4-Nov-11 6:36 
GeneralXml integration for object position and size Pinmembersleekyworm26-Nov-10 22:58 
GeneralHide Tracker Handles Pinmemberchrisbray24-Mar-10 14:44 
GeneralRe: Hide Tracker Handles [modified] PinmemberAlireza Soleimani26-Mar-10 20:05 
GeneralRe: Hide Tracker Handles Pinmemberchrisbray27-Mar-10 0:43 
GeneralRe: Hide Tracker Handles PinmemberAlireza Soleimani28-Mar-10 12:03 
GeneralRe: Hide Tracker Handles Pinmemberchrisbray28-Mar-10 23:03 
GeneralRe: Hide Tracker Handles PinmemberMachineGun2-Nov-11 15:17 
GeneralRe: Hide Tracker Handles Pinmemberchrisbray2-Nov-11 20:52 
QuestionCan't find Canvas in my toolbox???? Pinmembersleezy27-Aug-09 14:44 
GeneralGreat! (VS2008 Required) Pinmemberjp2code26-Aug-09 9:57 
GeneralMy vote of 1 Pinmembersnehalshahprit29-May-09 17:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150224.1 | Last Updated 15 Mar 2010
Article Copyright 2009 by Alireza Soleimani
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid