我无法在以下代码中更改标签的位置:
public static void Initialize()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var F = new Form
{
BackColor = Color.Black,
TransparencyKey = Color.Black,
Bounds = Screen.PrimaryScreen.Bounds,
FormBorderStyle = FormBorderStyle.None,
Location = new Point(0, 0),
MinimumSize = new Size(1920, 1080),
TopMost = true
};
var Summoner1 = new Label
{
AutoSize = true,
Text = "Summoner Flashs in 20",
Dock = DockStyle.Fill,
ForeColor = Color.White,
Font = new Font("Consolas", 12),
Location = new Point(0, 500)
};
var Summoner2 = new Label
{
AutoSize = true,
Text = "Test",
Dock = DockStyle.Fill,
ForeColor = Color.White,
Font = new Font("Consolas", 12),
Location = new Point(40, 20)
};
var Summoner3 = new Label
{
AutoSize = false,
Text = "Summoner Flash in 20",
Dock = DockStyle.Fill,
ForeColor = Color.White,
Font = new Font("Consolas", 12),
Location = new Point(0, 0)
};
var Summoner4 = new Label
{
AutoSize = false,
Text = "Summoner Flash in 20",
Dock = DockStyle.Fill,
ForeColor = Color.White,
Font = new Font("Consolas", 12),
Location = new Point(0, 0)
};
var Summoner5 = new Label
{
AutoSize = false,
Text = "Summoner Flash in 20",
Dock = DockStyle.Fill,
ForeColor = Color.White,
Font = new Font("Consolas", 12),
Location = new Point(0, 0)
};
F.Controls.Add(Summoner1);
F.Controls.Add(Summoner2);
Application.Run(F);
}
我有代码:
Location = new Point(0, 500)
但它似乎出现在0,0,无论我放在那里,这使得它看起来只有Summoner1标签初始化,而不是其余的(我用Summoner1和Summoner2试过) 。它的问题是什么?
答案 0 :(得分:1)
删除DockStyle.Fill。无论您设置的位置如何,此属性都会将您的标签扩展为填写表单。填充意味着从位置0,0开始到表单的大小
其他标签也是如此。最后,表单引擎呈现的最后一个将覆盖所有其他
var Summoner1 = new Label
{
AutoSize = true,
Text = "Summoner Flashs in 20",
// Dock = DockStyle.Fill,
ForeColor = Color.White,
Font = new Font("Consolas", 12),
Location = new Point(0, 500)
};