我的表格顶部有一个图像,位于点(0,5)。我有一个带有部门名称的标签,尺寸也各不相同。我希望它始终是该图像右侧的X个像素。我该怎么做呢?我在我的问题中加入了“左”,因为它同样重要。以下是我目前的情况。
//
//deptName
//
this.deptName = new System.Windows.Forms.Label();
this.deptName.Text = CallTrak.dept_name;
this.deptName.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F);
this.deptName.Location = new System.Drawing.Point(300, 5); // looking to get this adjusted
this.deptName.ForeColor = System.Drawing.Color.White;
this.deptName.Size = new System.Drawing.Size(300, 300);
//
// companylogo
//
this.companylogo = new System.Windows.Forms.PictureBox();
switch (CallTrak.user_id)
{
case "1":
this.companylogo.Image = global::Call_Tracker.Properties.Resources._1;
break;
case "2":
this.companylogo.Image = global::Call_Tracker.Properties.Resources._2;
break;
case "3":
this.companylogo.Image = global::Call_Tracker.Properties.Resources._3;
break;
case "4":
this.companylogo.Image = global::Call_Tracker.Properties.Resources._4;
break;
case "5":
this.companylogo.Image = global::Call_Tracker.Properties.Resources._5;
break;
case "6":
this.companylogo.Image = global::Call_Tracker.Properties.Resources._6;
break;
}
this.companylogo.Location = new System.Drawing.Point(0, 5);
this.companylogo.Name = "companylogo";
this.companylogo.Size = new System.Drawing.Size(200, 106);
this.companylogo.TabIndex = 1;
this.companylogo.TabStop = false;
答案 0 :(得分:1)
我认为它是winforms,在global::Call_traker
事情中不太确定。
请勿直接修改blablabla.Designer.cs
个文件。
默认情况下,标签是自动调整的。您可以设置标签文本,然后检查其大小,获取表单大小(您可能必须使用Client...
大小/矩形)或图片框并执行您要执行的任何操作,例如:
deptName.Text = "blablabla";
if(left)
deptName.Location = new Location(companylogo.Left + left, companylogo.Top);
if(right)
deptName.Location = new Location(companylogo.Left + companylogo.Width - right, companylogo.Top);
标签应该在图片框之后添加才能看到(使用winform设计师将标签移到顶部)。
如果您询问布局(自动调整图片框右侧X像素后的位置标签),则您使用容器控件:FlowLayoutPanel
或TableLayoutPanel
。< / p>