Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 926505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:41:43+00:00 2026-05-15T19:41:43+00:00

int width, height; width = this.Size.Width; height = this.Size.Height; width /= 3; height /=

  • 0
int width, height;
width = this.Size.Width;
height = this.Size.Height;
width /= 3;
height /= 3;
btn_1.Size = new Size(width, height);

I am trying to make a button’s size and location change when the user resizes a form.

How can I assigning a size to a button?

I tried to make it with changing width and height separately. I know that I can make it by anchoring it, but I would like to make it with pure coding.
Also refreshing the form did not work. I can set the locations of buttons easily with the Location property, but the size property does not work. I couldn’t find the difference…

Here is the full code which works for changing the positions of objects, but does not work for changing the size:

private void form_counterMain_Resize(object sender, EventArgs e)
    {
        int width, height;
        Point templocation;
        templocation = new Point(0, 0);
        width = this.Size.Width;
        height = this.Size.Height;
        width /= 3;
        height /= 3;
        //:::location:::
        btn_1.Location = templocation;
        templocation.X = width;
        btn_2.Location = templocation;
        templocation.X = width * 2;
        btn_3.Location = templocation;
        templocation.X = 0;
        templocation.Y = height;
        btn_4.Location = templocation;
        templocation.X = width;
        btn_5.Location = templocation;
        templocation.X = width * 2;
        btn_6.Location = templocation;
        templocation.Y = height * 2;
        templocation.X = 0;
        btn_7.Location = templocation;
        templocation.X = width;
        btn_8.Location = templocation;
        templocation.X = width * 2;
        btn_9.Location = templocation;

        //:::size:::
        btn_1.Size = new Size(width, height);
        this.Refresh();
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:41:44+00:00Added an answer on May 15, 2026 at 7:41 pm

    I couldn’t manage to find it out, why it does not change it with my code while it works with Jamie’s code. But instead of working on that, i created 9 buttons with pure code. So it gave me ability to change every property.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace hw02
    {
    public partial class form_counterMain : Form
    {
        int[] b=new int[9]; //initialized the counters
        Button[] btn= new Button[9]; //initialized the buttons
    
    
        public form_counterMain()
        {
            for (int t = 0; t < 9; t++) //this loop makes all the counters 0
            {
                b[t] = 0;
            }
            for (int t = 0; t < 9;t++) //this loop makes all the buttons assigned to a button
            {
                btn[t]=new Button();
            }
            InitializeComponent();
            changeFunc(); //first calculation
            btn[0].Click += new System.EventHandler(btn0Click); //here i assign the functions to buttons
            btn[1].Click += new System.EventHandler(btn1Click);
            btn[2].Click += new System.EventHandler(btn2Click);
            btn[3].Click += new System.EventHandler(btn3Click);
            btn[4].Click += new System.EventHandler(btn4Click);
            btn[5].Click += new System.EventHandler(btn5Click);
            btn[6].Click += new System.EventHandler(btn6Click);
            btn[7].Click += new System.EventHandler(btn7Click);
            btn[8].Click += new System.EventHandler(btn8Click);
    
        }
        private void form_counterMain_Resize(object sender, EventArgs e)
        {
            changeFunc();
        }
        private void changeFunc()
        {
            int width, height;
            Point templocation = new Point(0, 0);
            width = this.Size.Width;
            height = this.Size.Height;
            width = width/3 -5; //here i calculated the best values for 3 buttons
            height = height/3-12;
            for (int i = 0; i < 9; i++) //here i assign some necessary values to buttons and read the count numbers from memory
            {
                btn[i].Name = "btn_" + i; //the names are changed!
                btn[i].TabIndex = i;
                btn[i].Text = b[i].ToString();
                btn[i].Size = new Size(width, height);
                btn[i].Visible = true;
                btn[i].Parent = this;
                btn[i].FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    
            }
            //this lines sets the location of the buttons
            btn[0].Location = templocation;
            templocation.X = width;
            btn[1].Location = templocation;
            templocation.X = width * 2;
            btn[2].Location = templocation;
            templocation.X = 0;
            templocation.Y = height;
            btn[3].Location = templocation;
            templocation.X = width;
            btn[4].Location = templocation;
            templocation.X = width * 2;
            btn[5].Location = templocation;
            templocation.Y = height * 2;
            templocation.X = 0;
            btn[6].Location = templocation;
            templocation.X = width;
            btn[7].Location = templocation;
            templocation.X = width * 2;
            btn[8].Location = templocation;
    
        }
        //here the functions start, they only increase the integers in the memory and then they force the program to refresh its visual state
        private void btn0Click(Object sender, EventArgs e)
        {
            b[0]++;
            changeFunc();
        }
        private void btn1Click(Object sender, EventArgs e)
        {
            b[1]++;
            changeFunc();
        }
        private void btn2Click(Object sender, EventArgs e)
        {
            b[2]++;
            changeFunc();
        }
        private void btn3Click(Object sender, EventArgs e)
        {
            b[3]++;
            changeFunc();
        }
        private void btn4Click(Object sender, EventArgs e)
        {
            b[4]++;
            changeFunc();
        }
        private void btn5Click(Object sender, EventArgs e)
        {
            b[5]++;
            changeFunc();
        }
        private void btn6Click(Object sender, EventArgs e)
        {
            b[6]++;
            changeFunc();
        }
        private void btn7Click(Object sender, EventArgs e)
        {
            b[7]++;
            changeFunc();
        }
        private void btn8Click(Object sender, EventArgs e)
        {
            b[8]++;
            changeFunc();
        }
    
    }
    }
    

    I don’t know if someone needs the code, i just pasted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public function bmdToStr(bmd:BitmapData,width:int,height:int):String { var encoder:JPEGEncoder = new JPEGEncoder(); var encBytes:ByteArray = encoder.encode(bmd); return
- (void) rgbMatrix:(UIImage *)i toRGB:(uint32_t **)rgbArray{ int m_width = i.size.width; int m_height = i.size.height;
I have the following code: int width = 10; int height = 7; bool[,]
I have a class defined as: class Obj { public: int width, height; Obj(int
protected IplImage processImage(byte[] data, int width, int height) { int f = 4;// SUBSAMPLING_FACTOR;
private void save(Rectangle src, Rectangle dest, string fName, int width, int height, Bitmap file)
The following table...: CREATE TABLE v ( height int, width int, depth int, volume
I have an int* of rgb data,width, height, and scanlinestride where i would like
This is my JFrame code: public static int width = 800; public static int
We have a Japanese user reporting that a form size is truncated (smaller size,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.