Resizing button size during run-time in C# with mouse

前端 未结 1 1064
眼角桃花
眼角桃花 2021-01-24 07:59

I am using following code to make and move buttons at runtime by mouse.

I want to also resize them with mouse. This code was provided by KekuSemau. Thanks a lot KekuSem

相关标签:
1条回答
  • 2021-01-24 08:56

    Controls (like button) in winforms usually have a size (width, height) and a location (x, y), where the units are pixels.

    Modifying those properties is relatively straightforward: this shows an example where clicking on a button will make it 10 px wider and 10 px higher, and also move it 10 px to the right and 10 px down.

      private void button1_Click(object sender, EventArgs e)
            {
                Button button = (Button)sender;
    
                button.Width = button.Width + 10;
                button.Height = button.Height + 10;
    
                button.Location = new Point(button.Location.X + 10, button.Location.Y + 10);
    
            }
    
    0 讨论(0)
提交回复
热议问题