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. Resize of Custom Control And Excluding control

Resize of Custom Control And Excluding control

Scheduled Pinned Locked Moved C#
csharpwinformsgraphicsdesignquestion
7 Posts 2 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.
  • S Offline
    S Offline
    Saksida Bojan
    wrote on last edited by
    #1

    Witch attribute I need to set, so that designer can resize control only vertical or horizontal Simular to Textbox. It can be resized only by width as long as it doesn't have Multiline property to true. Is there an if statement, so that code executing code is excluded, while the control is being rendered by Design view. Currently I am at work, so I don't have much time to google around. I have Read a Book "GDI+ Application Custom Controls with Visual C# 2005", This book is nearly an introduction to custom controls. Is there any book with more advance topics?

    L 1 Reply Last reply
    0
    • S Saksida Bojan

      Witch attribute I need to set, so that designer can resize control only vertical or horizontal Simular to Textbox. It can be resized only by width as long as it doesn't have Multiline property to true. Is there an if statement, so that code executing code is excluded, while the control is being rendered by Design view. Currently I am at work, so I don't have much time to google around. I have Read a Book "GDI+ Application Custom Controls with Visual C# 2005", This book is nearly an introduction to custom controls. Is there any book with more advance topics?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Saksida Bojan wrote:

      Witch attribute I need to set, so that designer can resize control only vertical or horizontal Simular to Textbox. It can be resized only by width as long as it doesn't have Multiline property to true.

      That's probably not done using an attribute, but by setting some maximum and minimum widths. Perhaps even guarding those, in the Resize-event.

      Saksida Bojan wrote:

      Currently I am at work, so I don't have much time to google around.

      :)

      I are Troll :suss:

      S 1 Reply Last reply
      0
      • L Lost User

        Saksida Bojan wrote:

        Witch attribute I need to set, so that designer can resize control only vertical or horizontal Simular to Textbox. It can be resized only by width as long as it doesn't have Multiline property to true.

        That's probably not done using an attribute, but by setting some maximum and minimum widths. Perhaps even guarding those, in the Resize-event.

        Saksida Bojan wrote:

        Currently I am at work, so I don't have much time to google around.

        :)

        I are Troll :suss:

        S Offline
        S Offline
        Saksida Bojan
        wrote on last edited by
        #3

        Eddy Vluggen wrote:

        That's probably not done using an attribute, but by setting some maximum and minimum widths. Perhaps even guarding those, in the Resize-event.

        Does not help. Even if I set Minimum and maximum width, designer still shows that can be resized in any direction. Look at Textbox and notice you can't change height, because simply you can't grab on resize rectangle when control is selceted

        L 1 Reply Last reply
        0
        • S Saksida Bojan

          Eddy Vluggen wrote:

          That's probably not done using an attribute, but by setting some maximum and minimum widths. Perhaps even guarding those, in the Resize-event.

          Does not help. Even if I set Minimum and maximum width, designer still shows that can be resized in any direction. Look at Textbox and notice you can't change height, because simply you can't grab on resize rectangle when control is selceted

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Saksida Bojan wrote:

          Does not help. Even if I set Minimum and maximum width, designer still shows that can be resized in any direction. Look at Textbox and notice you can't change height, because simply you can't grab on resize rectangle when control is selceted

          I found this solution on SO[^], which you probably already tried;

          protected override void SetBoundsCore(int x, int y,
          int width, int height, BoundsSpecified specified)
          {
          if (this.DesignMode)
          base.SetBoundsCore(x, y, 500, 490, specified);
          else
          base.SetBoundsCore(x, y, width, height, specified);
          }

          I are Troll :suss:

          S 2 Replies Last reply
          0
          • L Lost User

            Saksida Bojan wrote:

            Does not help. Even if I set Minimum and maximum width, designer still shows that can be resized in any direction. Look at Textbox and notice you can't change height, because simply you can't grab on resize rectangle when control is selceted

            I found this solution on SO[^], which you probably already tried;

            protected override void SetBoundsCore(int x, int y,
            int width, int height, BoundsSpecified specified)
            {
            if (this.DesignMode)
            base.SetBoundsCore(x, y, 500, 490, specified);
            else
            base.SetBoundsCore(x, y, width, height, specified);
            }

            I are Troll :suss:

            S Offline
            S Offline
            Saksida Bojan
            wrote on last edited by
            #5

            I am sorry for late reply, but this code does exactly as i would use resize event or setting min and max size. this.DesignMode is part of an answer and i thank you for it. I have just found a book with more advance topics. I am sure it will be there. Thank you for your time

            1 Reply Last reply
            0
            • L Lost User

              Saksida Bojan wrote:

              Does not help. Even if I set Minimum and maximum width, designer still shows that can be resized in any direction. Look at Textbox and notice you can't change height, because simply you can't grab on resize rectangle when control is selceted

              I found this solution on SO[^], which you probably already tried;

              protected override void SetBoundsCore(int x, int y,
              int width, int height, BoundsSpecified specified)
              {
              if (this.DesignMode)
              base.SetBoundsCore(x, y, 500, 490, specified);
              else
              base.SetBoundsCore(x, y, width, height, specified);
              }

              I are Troll :suss:

              S Offline
              S Offline
              Saksida Bojan
              wrote on last edited by
              #6

              I Found the way to use what i wanted. I added a dll reference: system.Design.dll I added using System.Windows.Form.Design

              [ToolboxItem(true)]
              [Designer(typeof(testDesigner))] // Designer need
              public class test : Button
              {
              [Browsable(true)]
              public bool MultiLine
              {
              get
              {
              return testDesigner.m;
              }
              set
              {
              testDesigner.m = value;
              }
              }
              }
              public class testDesigner : ControlDesigner
              {
              public static bool m;
              public override SelectionRules SelectionRules
              {
              get
              {
              if (!m)
              return SelectionRules.LeftSizeable | SelectionRules.RightSizeable | SelectionRules.Visible | SelectionRules.Moveable;
              else
              return SelectionRules.BottomSizeable | SelectionRules.TopSizeable | SelectionRules.Visible | SelectionRules.Moveable;
              }
              }
              }

              L 1 Reply Last reply
              0
              • S Saksida Bojan

                I Found the way to use what i wanted. I added a dll reference: system.Design.dll I added using System.Windows.Form.Design

                [ToolboxItem(true)]
                [Designer(typeof(testDesigner))] // Designer need
                public class test : Button
                {
                [Browsable(true)]
                public bool MultiLine
                {
                get
                {
                return testDesigner.m;
                }
                set
                {
                testDesigner.m = value;
                }
                }
                }
                public class testDesigner : ControlDesigner
                {
                public static bool m;
                public override SelectionRules SelectionRules
                {
                get
                {
                if (!m)
                return SelectionRules.LeftSizeable | SelectionRules.RightSizeable | SelectionRules.Visible | SelectionRules.Moveable;
                else
                return SelectionRules.BottomSizeable | SelectionRules.TopSizeable | SelectionRules.Visible | SelectionRules.Moveable;
                }
                }
                }

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Cool :cool: Thanks for sharing :)

                I are Troll :suss:

                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