Click here to Skip to main content
Licence CPOL
First Posted 29 May 2009
Views 27,001
Downloads 661
Bookmarked 45 times

Custom Windows Panel

By | 15 Mar 2010 | Article
Every control in this panel can change the size and move on the panel

Introduction

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)
{
base.OnControlAdded(e);
if (e.Control is Tracker)
return;

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);
}
...
}

History

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

License

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)

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
SuggestionDoesn't work when scrolled off the screen PinmemberMachineGun14:16 2 Nov '11  
GeneralRe: Doesn't work when scrolled off the screen Pinmemberchrisbray19:59 2 Nov '11  
GeneralRe: Doesn't work when scrolled off the screen PinmemberMachineGun5:00 4 Nov '11  
GeneralRe: Doesn't work when scrolled off the screen Pinmemberchrisbray5:18 4 Nov '11  
GeneralRe: Doesn't work when scrolled off the screen PinmemberMachineGun5:36 4 Nov '11  
GeneralXml integration for object position and size Pinmembersleekyworm21:58 26 Nov '10  
GeneralHide Tracker Handles Pinmemberchrisbray13:44 24 Mar '10  
GeneralRe: Hide Tracker Handles [modified] PinmemberAlireza Soleimani19:05 26 Mar '10  
GeneralRe: Hide Tracker Handles Pinmemberchrisbray23:43 26 Mar '10  
GeneralRe: Hide Tracker Handles PinmemberAlireza Soleimani11:03 28 Mar '10  
GeneralRe: Hide Tracker Handles Pinmemberchrisbray22:03 28 Mar '10  
GeneralRe: Hide Tracker Handles PinmemberMachineGun14:17 2 Nov '11  
GeneralRe: Hide Tracker Handles Pinmemberchrisbray19:52 2 Nov '11  
QuestionCan't find Canvas in my toolbox???? Pinmembersleezy13:44 27 Aug '09  
GeneralGreat! (VS2008 Required) Pinmemberjp2code8:57 26 Aug '09  
GeneralMy vote of 1 Pinmembersnehalshahprit16:30 29 May '09  

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.

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