C# form, Control Area

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jvandyk
    New Member
    • Mar 2008
    • 5

    C# form, Control Area

    Hi, I'm busy creating new GUI's and have come up against a bit of a wall. I can create my form in any shape I want using GraphicsPath and Region. However there is a set area in my forms that I want any controls to be created.

    The best way I can explain this is for example, if you have a form with padding all(8) the controls on the form will fall into this inner rectange.

    How can I create an area on my form that acts similar to padding?
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Can you add a Panel control to your form and anchor it about 8px from the sides on all sides?
    And then like disable the form?

    Comment

    • jvandyk
      New Member
      • Mar 2008
      • 5

      #3
      yeah, but I'm trying to do this in a more pure format. so that my form class doesn't have any other controls on it other than what I've created internally.

      There must be a way to set like a "child client area" that all child objects on the form would fall into.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Make it an MDI parent?

        Comment

        • jvandyk
          New Member
          • Mar 2008
          • 5

          #5
          Perhaps I'm not making myself clear as to what im trying to do.

          Ive created a UserControl inherited from the Form.
          my FormClass then has a specific shape created by settings its region to a graphics path I have created.

          I've also created a whole bunch of other properties and methods to control the movement, resize etc for my FormClass.

          So basically I've created a form with a specific border shape and with all the properties that I want.

          however, If I create a new project and inherit Form1 from my FormClass, I can place controls anywhere I want on it. This means however that sometime a control may only be half visible on the form, because my forms shaped region cuts off some of it.

          So what I want to do is set aside a specific area on the form that all chils objects will have to be placed.

          I however dont want this. if i drag for create a control in the forms container I want them to be created in a specific region that is inherited of my form class.

          I want it to act like a normal form. so any other developer can use it thus.
          Last edited by jvandyk; Mar 31 '08, 03:03 PM. Reason: very bad grammer

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Since your usercontrol inherits from the form class, you should be able to override it's default container (.Controls is the property)
            You could then do as I suggested and make a Panel that is anchored 8px (or whatever) away from the edges, then when someone calls .Controls (which would be done by the designer to add controls to your form/usercontrol), you would return the .Controls property of the Panel and not of your underlying form.

            Comment

            • jvandyk
              New Member
              • Mar 2008
              • 5

              #7
              Ah, that makes sense. I'm still going to try do this without actually adding a panel, but you have definately put me on the right track. I'm going to look at overriding the OnControlAdded event, and see where it takes me.

              Thanks.

              Comment

              • jvandyk
                New Member
                • Mar 2008
                • 5

                #8
                Ok I sort of got what I wanted working. to do this I put in the following code:
                Code:
                public frm()
                        {
                            InitializeComponent();
                            this.Padding = new Padding(0, 0, 0, 0); 
                            //This above will then initiate the new Padding call;
                        }
                
                 public new Padding Padding 
                        { 
                            get 
                            {
                                Padding _Padding = base.Padding;
                                _Padding.Top -= 20;
                                return _Padding; 
                            }
                            set 
                            {
                                value.Top += 20;
                                base.Padding = new Padding(
                value.Left, 
                value.Top, 
                value.Right, 
                value.Bottom);                 
                            } 
                        }
                //-------------------------------------------------

                Ok the idea here is that even when the user specifies a padding of (0,0,0,0) they will get a padding of (0,20,0,0) and although they will be able to see this on the screen, the padding will still tell them the top padding is (0).

                Ideally I'll change the (20) value to the height of my title bar, and the left right and top to whatever bordering I want.

                This way I dont need to create any extra controls on my form to handle my control region.

                However I would still like to fiugre out a way so I can create different control regions on my form. but this will do for now.

                Thanks for all the help.If I had paid a bit closer attention yesterday I might have figured it out from your first reply.

                Comment

                Working...