Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Reduce the container zone of a panel.

Reduce the container zone of a panel.

Scheduled Pinned Locked Moved C#
csharphelpdotnetdesigndocker
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    galinace
    wrote on last edited by
    #1

    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?

    T C 2 Replies Last reply
    0
    • G galinace

      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?

      T Offline
      T Offline
      TheGreatAndPowerfulOz
      wrote on last edited by
      #2

      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[^]

      1 Reply Last reply
      0
      • G galinace

        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?

        C Offline
        C Offline
        Curtis Schlak
        wrote on last edited by
        #3

        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

        G 1 Reply Last reply
        0
        • C Curtis Schlak

          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

          G Offline
          G Offline
          galinace
          wrote on last edited by
          #4

          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

          C 1 Reply Last reply
          0
          • G galinace

            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

            C Offline
            C Offline
            Curtis Schlak
            wrote on last edited by
            #5

            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

            G 2 Replies Last reply
            0
            • C Curtis Schlak

              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

              G Offline
              G Offline
              galinace
              wrote on last edited by
              #6

              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

              C 1 Reply Last reply
              0
              • C Curtis Schlak

                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

                G Offline
                G Offline
                galinace
                wrote on last edited by
                #7

                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
                
                C 1 Reply Last reply
                0
                • G galinace

                  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
                  
                  C Offline
                  C Offline
                  Curtis Schlak
                  wrote on last edited by
                  #8

                  Cool, thank you very much! Happy coding. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                  1 Reply Last reply
                  0
                  • G galinace

                    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

                    C Offline
                    C Offline
                    Curtis Schlak
                    wrote on last edited by
                    #9

                    Just posted the article. I don't know how long the link will last: Y(et)A(nother)TabControl.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups