私はWinFormsアプリケーションを作成しています。このアプリケーションでは、私は動的なLabel
,PictureBox
とTextBox
コントロールを生成します。C# - 親が設定されていても、ダイナミックラベルが透明でないのはなぜですか?
をPictureBox
にドラッグアンドドロップすると、TextBox
が追加されます。テキストを入力して「Enter」を押すと、以下のメソッドが起動されます。
private void tb_Tile_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
TextBox tb_Tile = sender as TextBox;
Tile tb_Tag = tb_Tile.Tag as Tile;
//add function that overgives the given name to the matrix i.e. GiveNameToMatrix()
tb_Tile.Visible = false;
Label lbl_Tile = Controls.Find("Label" + tb_Tag.X + tb_Tag.Y, true).FirstOrDefault() as Label;
lbl_Tile.Visible = true;
//find picture box by tag or sth and then make this pB the parent
PictureBox pb_Tile = (PictureBox)gb_gridBox.Controls["Tile" + tb_Tag.X + tb_Tag.Y];
pb_Tile.BackgroundImage = pb_Tile.Image;
lbl_Tile.Parent = pb_Tile;
// pb_Tile.Visible = false;
if (pb_Tile.HasChildren)
{
lbl_Tile.Text = tb_Tile.Text; //parent has to be set to PictureBox
lbl_Tile.Visible = true;
lbl_Tile.ForeColor = Color.Black;
lbl_Tile.BackColor = Color.Transparent;
lbl_Tile.Location = pb_Tile.Location;
lbl_Tile.Refresh();
pb_Tile.Refresh();
gb_gridBox.Controls.Add(lbl_Tile);
lbl_Tile.BringToFront();
}
}
}
私はLabel.Text
がPictureBox
上に表示することにしたいです。このため、PictureBox
をLabel
の親とし、Label.BackColor
を透明と設定しています。しかしLabel
がちょうどPictureBox
後ろに消え...
誰もがこれを解決するか、PictureBox
の前にテキストを示す別の可能性に私にヒントを与えることができる方法の手掛かりを持っていますか?
ありがとうございます。
コントロールの[z-order](https://msdn.microsoft.com/en-us/library/wh9zw57z(v=vs.110).aspx)の調整を試したことがありますか?例えば。 'lbl_Tile.BringToFront();' –
'gb_gridBox.Controls.SetChildIndex(lbl_tile、0);'を設定しようとしましたか? – Pikoh
ありがとう! はい、私はBringToFront()を使用しました。最後の行のいずれかに表示されています。 子インデックスを設定すると、ピクチャボックスの前にラベルが表示されますが、透明にはなりません。 – electrogandalf