Reduce the container zone of a panel.
-
Hi I’m trying to create my own component under .Net Framework 2.0 in C#. I have a problem on reducing the surface where component can be drop. In fact I would like to have the exact comportment of a winform : one part of my control would be a design surface like the title bar in a form (non accessible by the designer or other control) and an other part would be the container which add controls and where they can draw themselves. Is there anybody who can help me?
-
Hi I’m trying to create my own component under .Net Framework 2.0 in C#. I have a problem on reducing the surface where component can be drop. In fact I would like to have the exact comportment of a winform : one part of my control would be a design surface like the title bar in a form (non accessible by the designer or other control) and an other part would be the container which add controls and where they can draw themselves. Is there anybody who can help me?
I am assuming you are inheriting from ControlContainer which ultimately inherits from Control. So, you would need to override (from Control) OnDragEnter OnDragLeave OnDragDrop OnDragOver and possibly OnMouseMove OnMouseHover There is an example here: Control.DragOver Event[^]
-
Hi I’m trying to create my own component under .Net Framework 2.0 in C#. I have a problem on reducing the surface where component can be drop. In fact I would like to have the exact comportment of a winform : one part of my control would be a design surface like the title bar in a form (non accessible by the designer or other control) and an other part would be the container which add controls and where they can draw themselves. Is there anybody who can help me?
You know, I am preparing an article on a replacement tab control that I just wrote that has this exact feature. Admittedly, it's authored in .NET 1.1, but I think the concepts will remain the same. (I haven't tried the .NET 2.0 stuff, yet.) Here are the steps that I used to do this. 1. Override the DisplayRect to return the amount of area that you want the client to use. 2. Derive a new class from Control.ControlCollection that passes through requests for controls to the first child of your control. 3. Override Control.CreateControlCollection to return the class that you created in step 2. 4. Make the first (and only) child of your control a Panel with Dock = DockStyle.Fill. If I'm not mistaken, that should do it. If that's not clear (and I hate to do this) you can always wait for my article. The working title is YaTabControl (Yet Another....). Hope that helps. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty
-
You know, I am preparing an article on a replacement tab control that I just wrote that has this exact feature. Admittedly, it's authored in .NET 1.1, but I think the concepts will remain the same. (I haven't tried the .NET 2.0 stuff, yet.) Here are the steps that I used to do this. 1. Override the DisplayRect to return the amount of area that you want the client to use. 2. Derive a new class from Control.ControlCollection that passes through requests for controls to the first child of your control. 3. Override Control.CreateControlCollection to return the class that you created in step 2. 4. Make the first (and only) child of your control a Panel with Dock = DockStyle.Fill. If I'm not mistaken, that should do it. If that's not clear (and I hate to do this) you can always wait for my article. The working title is YaTabControl (Yet Another....). Hope that helps. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty
Hi thanks for your post. I'll be very interested on your article about tab control (I'll have to work on this problem in a few day). About the problem of reducing the displayrectangle of my control. I tried the first point you saied
Curtis S. wrote:
1. Override the DisplayRect to return the amount of area that you want the client to use.
The result is :
public override Rectangle DisplayRectangle { get { Rectangle rec = base.DisplayRectangle; return new Rectangle( rec.X+(int)this._epaisseurBord, rec.Y+(int)this._tailleBarTitre, (int)(rec.Width-this._epaisseurBord*2), (int)(rec.Height-this._tailleBarTitre-this._epaisseurBord)); } }
(sorry for the french name of my properties :) ) The problem is I have no result. The breakpoint i used in debug mode show that this property is nerver acces. At the end controls like button or label appear where ever they want on all the surface of my control. The other point you told me are much more for a tabcontrol I think because the goal of my control is to have no control on it but can receive some. Do you have an idea about why that doesn't work ??? Thanks for all -- modified at 4:39 Saturday 17th December, 2005
-
Hi thanks for your post. I'll be very interested on your article about tab control (I'll have to work on this problem in a few day). About the problem of reducing the displayrectangle of my control. I tried the first point you saied
Curtis S. wrote:
1. Override the DisplayRect to return the amount of area that you want the client to use.
The result is :
public override Rectangle DisplayRectangle { get { Rectangle rec = base.DisplayRectangle; return new Rectangle( rec.X+(int)this._epaisseurBord, rec.Y+(int)this._tailleBarTitre, (int)(rec.Width-this._epaisseurBord*2), (int)(rec.Height-this._tailleBarTitre-this._epaisseurBord)); } }
(sorry for the french name of my properties :) ) The problem is I have no result. The breakpoint i used in debug mode show that this property is nerver acces. At the end controls like button or label appear where ever they want on all the surface of my control. The other point you told me are much more for a tabcontrol I think because the goal of my control is to have no control on it but can receive some. Do you have an idea about why that doesn't work ??? Thanks for all -- modified at 4:39 Saturday 17th December, 2005
That property will not get used unless the child has some kind of Dock style other than
DockStyle.None
. Unfortunately, that solution that I gave to you only works if all steps get done. Sorry. It was the only way that I could find to do what we both wanted. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty -
That property will not get used unless the child has some kind of Dock style other than
DockStyle.None
. Unfortunately, that solution that I gave to you only works if all steps get done. Sorry. It was the only way that I could find to do what we both wanted. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty -
That property will not get used unless the child has some kind of Dock style other than
DockStyle.None
. Unfortunately, that solution that I gave to you only works if all steps get done. Sorry. It was the only way that I could find to do what we both wanted. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertaintyHi, I sent the same post on the MSDN's forum and received an other way of doing what we both wanted. I didn't try it for the moment but wanted to keep you informed. You can follow this URL : http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=172709&SiteID=1[^] to see the entire conversation but this is the answer of Jelle van der Beek. "The zone in which components cannot be dropped is called the non-client area. There is no support in the .NET framework for the non-client area, but you can still control it by overriding the WM_NC* messages. Here is a piece of sample code that will set the non-client border to 10 pixels wide."
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; using System.Runtime.InteropServices; namespace Foo { public class SomeControl : Control { public SomeControl() { SetStyle( ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true ); } protected override void WndProc( ref Message m ) { switch( m.Msg ) { case 0x0083: // WM_NCCALCSIZE if( m.WParam == IntPtr.Zero ){ RecalcNonClientArea( m.LParam ); } else if( m.WParam == new IntPtr(1) ){ RecalcNonClientArea( m.LParam ); } break; case 0x0085: // WM_NCPAINT IntPtr hDC = WinApi.GetWindowDC( m.HWnd ); if( hDC != IntPtr.Zero ){ using( Graphics maing = Graphics.FromHdc(hDC) ){ // // PAINT HERE // } WinApi.ReleaseDC( m.HWnd, hDC ); } m.Result = IntPtr.Zero; break; } base.WndProc( ref m ); } private void RecalcNonClientArea( IntPtr lParam ) { WinApi.NCCALCSIZE_PARAMS csp; csp = (WinApi.N
-
Hi, I sent the same post on the MSDN's forum and received an other way of doing what we both wanted. I didn't try it for the moment but wanted to keep you informed. You can follow this URL : http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=172709&SiteID=1[^] to see the entire conversation but this is the answer of Jelle van der Beek. "The zone in which components cannot be dropped is called the non-client area. There is no support in the .NET framework for the non-client area, but you can still control it by overriding the WM_NC* messages. Here is a piece of sample code that will set the non-client border to 10 pixels wide."
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; using System.Runtime.InteropServices; namespace Foo { public class SomeControl : Control { public SomeControl() { SetStyle( ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true ); } protected override void WndProc( ref Message m ) { switch( m.Msg ) { case 0x0083: // WM_NCCALCSIZE if( m.WParam == IntPtr.Zero ){ RecalcNonClientArea( m.LParam ); } else if( m.WParam == new IntPtr(1) ){ RecalcNonClientArea( m.LParam ); } break; case 0x0085: // WM_NCPAINT IntPtr hDC = WinApi.GetWindowDC( m.HWnd ); if( hDC != IntPtr.Zero ){ using( Graphics maing = Graphics.FromHdc(hDC) ){ // // PAINT HERE // } WinApi.ReleaseDC( m.HWnd, hDC ); } m.Result = IntPtr.Zero; break; } base.WndProc( ref m ); } private void RecalcNonClientArea( IntPtr lParam ) { WinApi.NCCALCSIZE_PARAMS csp; csp = (WinApi.N
Cool, thank you very much! Happy coding. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty
-
Thank you very much. I will try with a child panel with it dockstyle at fill. I hope that won't reduce the executive time. I will told you if I find an other solution. With the pleasure to read your artical very soon
Just posted the article. I don't know how long the link will last: Y(et)A(nother)TabControl.