请问在自定的绘制矩形中要放入一个控件(例如,TextBox,Label,ComboBox…), 想要设定这个控件在矩形中的位置(置左,置中,置右), 可以怎么做呢? 
需要自行计算坐标吗? 这样并不准确, 怎么做会比较好呢?

解决方案 »

  1.   

    需要自己计算坐标,例如下:            // 
                // labelDesc
                // 
                this.labelDesc.AutoSize = true;
                this.labelDesc.Location = new System.Drawing.Point(32, 24);
                this.labelDesc.Name = "labelDesc";
                this.labelDesc.Size = new System.Drawing.Size(54, 17);
                this.labelDesc.TabIndex = 1;
                this.labelDesc.Text = "异常描述";
                // 
                // textBoxDetail
                // 
                this.textBoxDetail.Location = new System.Drawing.Point(8, 112);
                this.textBoxDetail.Multiline = true;
                this.textBoxDetail.Name = "textBoxDetail";
                this.textBoxDetail.ReadOnly = true;
                this.textBoxDetail.ScrollBars = System.Windows.Forms.ScrollBars.Both;
                this.textBoxDetail.Size = new System.Drawing.Size(560, 336);
                this.textBoxDetail.TabIndex = 2;
                this.textBoxDetail.Text = "";            this.Controls.Add(this.labelDesc);
                this.Controls.Add(this.buttonDetail);
      

  2.   

    其中this.textBoxDetail.Location = new System.Drawing.Point(8, 112);就是用来指定控件在窗体中的位置的
      

  3.   

    to : 在自定的绘制矩形中要放,.....如果是图形画矩形,需要计算坐标,并this.textBoxDetail.Location = new System.Drawing.Point()如果是控件,可以设置需要加入的控件的 parent 属性 和 dock属性. 这样能控制控件的坐标