我已经创建了这个功能,创建标签在正确的位置与正确的文本.我使应用程序3840x1080,他们是不可见的也没有任何屏幕外的标签.如果我做的是完全不符合标准或直线上升愚蠢,请至少给我一个链接.
public void CreateTourPanel(string sittingArrangement,
string fromTo, string departureTime, string duration, string cost)
{
Point holderPos = new Point(12, 208);
Panel panelTemp = new Panel();
panelTemp.Size = new Size(470, 71);
panelTemp.Location = (new Point(19 + holderPos.X, 14 + (77 * (TourList.Count + 1)) + holderPos.Y));
for (int i = 0; i < 5; i++)
{
Label labelTemp = new Label();
switch (i)
{
case 0:
labelTemp.Location = (new Point(27 + 19 + holderPos.X,
22 + 14 + (77 * (TourList.Count + 1)) + holderPos.Y));
labelTemp.Text = sittingArrangement;
labelTemp.Font = ChangeFontSize(labelTemp.Font, 14);
break;
case 1:
labelTemp.Location = (new Point(3 + 19 + holderPos.X,
46 + 14 + (77 * (TourList.Count + 1)) + holderPos.Y));
labelTemp.Text = fromTo;
labelTemp.Font = ChangeFontSize(labelTemp.Font, 15);
break;
case 2:
labelTemp.Location = (new Point(190 + 19 + holderPos.X,
1 + 14 + (77 * (TourList.Count + 1)) + holderPos.Y));
labelTemp.Text = departureTime;
labelTemp.Font = ChangeFontSize(labelTemp.Font, 20);
break;
case 3:
labelTemp.Location = (new Point(192 + 19 + holderPos.X,
32 + 14 + (77 * (TourList.Count + 1)) + holderPos.Y));
labelTemp.Text = duration;
labelTemp.Font = ChangeFontSize(labelTemp.Font, 14);
break;
case 4:
labelTemp.Location = (new Point(373 + 19 + holderPos.X,
5 + 14 + (77 * (TourList.Count + 1)) + holderPos.Y));
labelTemp.Text = cost;
labelTemp.Font = ChangeFontSize(labelTemp.Font, 20);
break;
}
panelTemp.Controls.Add(labelTemp);
}
panel3.Controls.Add(panelTemp);
TourList.Add(panelTemp);
}
Font ChangeFontSize(Font font, float size)
{
return new Font(font.FontFamily, size, font.Style);
}
字符串
我已经尝试用Contains代替Controls,用PointToScreen代替Location
1条答案
按热度按时间s6fujrry1#
由于
panelTemp
是labelTemp
对象的父对象,所以它们的Bounds
矩形必须落在panelTemp
的ClientRectangle
内。字符串
的数据
Y
的计算结果并不接近。你最好把它们都设置为0,因为至少现在它们是可见的。的
型