在C中,动态改变`GroupBox`的大小可以通过访问其`Width`和`Height`属性来实现。以下是一个简单的示例,演示了如何在Windows窗体应用程序中动态改变`GroupBox`的大小。
```csharp
using System;
using System.Windows.Forms;
public class DynamicGroupBoxForm : Form
{
private GroupBox groupBox;
public DynamicGroupBoxForm()
{
// 创建GroupBox
groupBox = new GroupBox();
groupBox.Text = "Dynamic GroupBox";
groupBox.Location = new System.Drawing.Point(10, 10);
groupBox.Size = new System.Drawing.Size(200, 100); // 初始大小
// 添加到窗体
this.Controls.Add(groupBox);
// 添加按钮来改变GroupBox的大小
Button changeSizeButton = new Button();
changeSizeButton.Text = "Change Size";
changeSizeButton.Location = new System.Drawing.Point(10, 120);
changeSizeButton.Click += new EventHandler(ChangeSizeButton_Click);
this.Controls.Add(changeSizeButton);