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. How to align the control in the centre.

How to align the control in the centre.

Scheduled Pinned Locked Moved C#
helpcsharpwinformstutorial
4 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.
  • P Offline
    P Offline
    Pankaj Nikam
    wrote on last edited by
    #1

    I have made some user controls. I will be using them in another application in C# where these will be added on the form dynamically at the click of a button. The sizes of the user controls differ from one another. The problem is that when I add them dynamically it aligns itself at the top left corner. I want it to automatically align itself to centre of the main form and when I resize the form, it should realign itself. I have tried setting its dock property to fill but it doesn't help at all.

    Always Keep Smiling. Yours Pankaj Nikam

    X L 2 Replies Last reply
    0
    • P Pankaj Nikam

      I have made some user controls. I will be using them in another application in C# where these will be added on the form dynamically at the click of a button. The sizes of the user controls differ from one another. The problem is that when I add them dynamically it aligns itself at the top left corner. I want it to automatically align itself to centre of the main form and when I resize the form, it should realign itself. I have tried setting its dock property to fill but it doesn't help at all.

      Always Keep Smiling. Yours Pankaj Nikam

      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #2

      use Resize event of form and put all controls in a panel then update its location. eg

      panel.Location = new Point(this.Width/2 - panel.Width/2, this.Height/2-panel.Height/2);

      TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

      P 1 Reply Last reply
      0
      • X Xmen Real

        use Resize event of form and put all controls in a panel then update its location. eg

        panel.Location = new Point(this.Width/2 - panel.Width/2, this.Height/2-panel.Height/2);

        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

        P Offline
        P Offline
        Pankaj Nikam
        wrote on last edited by
        #3

        Thank you so much. :)

        Always Keep Smiling. Yours Pankaj Nikam

        1 Reply Last reply
        0
        • P Pankaj Nikam

          I have made some user controls. I will be using them in another application in C# where these will be added on the form dynamically at the click of a button. The sizes of the user controls differ from one another. The problem is that when I add them dynamically it aligns itself at the top left corner. I want it to automatically align itself to centre of the main form and when I resize the form, it should realign itself. I have tried setting its dock property to fill but it doesn't help at all.

          Always Keep Smiling. Yours Pankaj Nikam

          L Offline
          L Offline
          Luis Alonso Ramos
          wrote on last edited by
          #4

          Put everything into a panel, and set that panel's Anchor property to none.

          Luis Alonso Ramos Intelectix Chihuahua, Mexico My Blog!

          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