using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private Label lbl = null; private void Form1_Load(object sender, EventArgs e) { lbl = new Label(); lbl.Text = "入力してください。"; lbl.Cursor = Cursors.IBeam; lbl.Click += lbl_Click; lbl.Anchor = AnchorStyles.Right; lbl.AutoSize = true; lbl.BackColor = Color.Transparent; lbl.ForeColor = Color.Gray; textBox1.Enter += lbl_Click; textBox1.Leave += textBox1_Leave; textBox1.Controls.Add(lbl); } void textBox1_Leave(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox1.Text)) { lbl.Visible = true; } } void lbl_Click(object sender, EventArgs e) { this.lbl.Visible = false; this.textBox1.Focus(); } } }