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 adjust button's location

How to adjust button's location

Scheduled Pinned Locked Moved C#
questionhelptutorial
3 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
    Sokka93
    wrote on last edited by
    #1

    How can I add a button when run time? and if there is a button in the form, how can it added next to it? Could you help me,please? Thanks in advance.

    S 1 Reply Last reply
    0
    • S Sokka93

      How can I add a button when run time? and if there is a button in the form, how can it added next to it? Could you help me,please? Thanks in advance.

      S Offline
      S Offline
      Simon P Stevens
      wrote on last edited by
      #2

      drago123 wrote:

      How can I add a button when run time?

      You just create the button and add it to the forms Controls collection.

      Button b = new Button();
      this.Controls.Add(b);

      drago123 wrote:

      and if there is a button in the form, how can it added next to it? Could you help me,please?

      You need to work out the position of the existing button, and position your new button alongside it.

      // Set the left position to be the same as the existing button.
      int left = existingButton.Left;
      // Plus the width of the existing button.
      left += existingButton.Width;
      // Plus a small gap.
      left += 20;

      // Set the top of the new button to be the same as the existing button.
      int top = existingButton.Top;

      // Create the new button.
      Button newButton = new Button();

      // Assign the left & top values to position the button.
      newButton.Left = left;
      newButton.Top = top;

      // Add the new button to the controls collection.
      this.Controls.Add(newButton);

      That help?

      Simon

      S 1 Reply Last reply
      0
      • S Simon P Stevens

        drago123 wrote:

        How can I add a button when run time?

        You just create the button and add it to the forms Controls collection.

        Button b = new Button();
        this.Controls.Add(b);

        drago123 wrote:

        and if there is a button in the form, how can it added next to it? Could you help me,please?

        You need to work out the position of the existing button, and position your new button alongside it.

        // Set the left position to be the same as the existing button.
        int left = existingButton.Left;
        // Plus the width of the existing button.
        left += existingButton.Width;
        // Plus a small gap.
        left += 20;

        // Set the top of the new button to be the same as the existing button.
        int top = existingButton.Top;

        // Create the new button.
        Button newButton = new Button();

        // Assign the left & top values to position the button.
        newButton.Left = left;
        newButton.Top = top;

        // Add the new button to the controls collection.
        this.Controls.Add(newButton);

        That help?

        Simon

        S Offline
        S Offline
        Sokka93
        wrote on last edited by
        #3

        thank you.

        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