zoukankan      html  css  js  c++  java
  • Winform 控件坐标定位

    控件的X,Y轴坐标都是相对外面一层容器的位置。如果控件在Panel1,Panel1又在Panel2,则控件坐标是根据Panel1计算。

    1、通过属性Location,可以在属性框设置。

    2、通过属性Left、Top,不在属性框里。

    using System;
    using System.Windows.Forms;
    
    namespace WindowsFormsApp1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                //第一种
                textBox1.Location = new System.Drawing.Point(150, 250);
                //X轴为100,Y轴0
                textBox1.Location = new System.Drawing.Point(100);
                //X,Y=(0,0)
                textBox1.Location = new System.Drawing.Point();
                //第四种 ,和第一种同效果
                textBox1.Location = new System.Drawing.Point(new System.Drawing.Size(150, 250));
    
                textBox1.Left = 190;
                textBox1.Top = 300;
    
                MessageBox.Show($"计算高度top+controlHeight:{(textBox1.Top + textBox1.Size.Height).ToString()}=textBox1.Bottom:{textBox1.Bottom}");
                MessageBox.Show($"计算高度left+controlWidth:{(textBox1.Left + textBox1.Size.Width).ToString()}=textBox1.Bottom:{textBox1.Right}");
            }
        }
    }
    量变会引起质变。
  • 相关阅读:
    实用 zsh 插件
    laravel 实用扩展包
    laravel Collection mapToDictionary 例子
    laravel mapSpread 例子
    mac 命令行大杂烩
    iview table中 on-view事件点击无效
    github网站打不开了
    iview table 表头样式修改
    $attrs is readonly
    iview中modal如何修改标题颜色
  • 原文地址:https://www.cnblogs.com/bibi-feiniaoyuan/p/winform_location.html
Copyright © 2011-2022 走看看