pictureBox/text. 等控件位置 Location=new Point(x,y),不能单独修改Control.Location.x或Control.Location.y,无法编译

​​​​​Control.Location 属性 (System.Windows.Forms) | Microsoft Learn

Control.Location 属性

  • 参考

反馈

定义

命名空间:

System.Windows.Forms

程序集:

System.Windows.Forms.dll

获取或设置该控件的左上角相对于其容器的左上角的坐标。

C#复制

public System.Drawing.Point Location { get; set; }
属性值

Point

Point,表示控件的左上角相对于其容器的左上角。

示例

下面的代码示例创建 GroupBox 并设置其一些常见属性。 该示例创建 并在 TextBox 分组框中设置其 Location 。 接下来,它设置 Text 组框的 属性,并将组框停靠到窗体的顶部。 最后,它通过将 属性设置为 Enabledfalse来禁用分组框,这会导致禁用组框中包含的所有控件。

C#复制

// Add a GroupBox to a form and set some of its common properties.
private void AddMyGroupBox()
{
   // Create a GroupBox and add a TextBox to it.
   GroupBox groupBox1 = new GroupBox();
   TextBox textBox1 = new TextBox();
   textBox1.Location = new Point(15, 15);
   groupBox1.Controls.Add(textBox1);

   // Set the Text and Dock properties of the GroupBox.
   groupBox1.Text = "MyGroupBox";
   groupBox1.Dock = DockStyle.Top;

   // Disable the GroupBox (which disables all its child controls)
   groupBox1.Enabled = false;

   // Add the Groupbox to the form.
   this.Controls.Add(groupBox1);
}

注解

Point由于 类是 Visual Basic 中 (Structure的值类型,struct在 Visual C#) 中,它由值返回,这意味着访问 属性将返回控件左上角点的副本。 因此,调整X从此属性返回的 的 Point 或 Y 属性不会影响控件的 LeftRight、 Top或 Bottom 属性值。 若要调整这些属性,请单独设置每个属性值,或使用新的 Point设置 属性Location

Control如果 为 ,Form则 Location 属性值表示屏幕坐标中的 左上角Form

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值