我在这里创建了一些代码来做水印,但是它不起作用。我需要知道如何控制水印的功能和方法。我正在尝试创建带有水印的表单。
就Powershell而言,我们只是初学者。
$TextBox1 = New-Object system.Windows.Forms.TextBox
$TextBox1.multiline = $false
$TextBox1.Name = "TextBox1"
$TextBox1.width = 100
$TextBox1.height = 20
$TextBox1.location = New-Object System.Drawing.Point(141,170)
$TextBox1.Font = 'Microsoft Sans Serif,10'
$WatermarkText = 'Enter Username'
$TextBox1.ForeColor = 'LightGray'
$TextBox1.Text = $WatermarkText
$TextBox1_Enter={
if($TextBox1.Text -eq $WatermarkText)
{
#Clear the text
$TextBox1.Text = ""
$TextBox1.ForeColor = 'WindowText'
}
}
$TextBox1_Leave={
if($TextBox1.Text -eq "")
{
#Display the watermark
$TextBox1.Text = $WatermarkText
$TextBox1.ForeColor = 'LightGray'
}
}
$TextBox1_VisibleChanged={
if($TextBox1.Visible -and $TextBox1.Tag -eq $null)
{
#Initialize the watermark and save it in the Tag property
$TextBox1.Tag = $TextBox1.Text;
$TextBox1.ForeColor = 'LightGray'
#If we have focus then clear out the text
if($TextBox1.Focused)
{
$TextBox1.Text = ""
$TextBox1.ForeColor = 'WindowText'
}
}
}
答案 0 :(得分:2)
您拥有的脚本块仅分配给变量,没有在$TextBox
对象上注册为事件处理程序。
使用类似$TextBox.Add_Enter( {#your code })
代替$TextBox_Enter={#your code }