.net - Vb.net在面板内的自定义文本上添加占位符
问题描述
我创建了一个继承面板的类,然后用Textbox
. 然后我尝试Textbox
使用以下代码添加水印/占位符:
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Dim sTxt As String = Me.Text
sTxt = IIf(sTxt.Length = 0, txt.Text, sTxt)
If m.Msg = &HF Then
If Not Me.Focused AndAlso String.IsNullOrEmpty(sTxt) AndAlso Not String.IsNullOrEmpty(Me.WaterMark) Then
Using g = Me.CreateGraphics()
TextRenderer.DrawText(g, Me.WaterMark, Me.Font, Me.ClientRectangle, Color.Red, Me.BackColor, TextFormatFlags.Top Or TextFormatFlags.Left)
End Using
End If
MyBase.Update()
End If
End Sub
我只尝试了该代码Textbox
并且WaterMark
确实出现了,但是当我尝试在我的自定义文本上使用它时,它WaterMark
永远不会出现。我认为问题是因为我在面板内WndProc
添加了一个,所以永远不会触发事件。Textbox
那么我怎样才能覆盖Panel_WndProc
to Txt_WndProc
?
解决方案
推荐阅读
- perl - 我可以通过 ssh 将本地变量回显到远程文件中吗?
- python - 数据帧中循环的并行处理
- c# - HAA0502 显式新引用类型分配
- .net - 按钮未在控制器类中执行正确的方法
- python - Tensorflow/Keras:未知:无法获得卷积算法
- regex - semver Release Candidate 正则表达式验证
- angularjs - AngularJS 在加载期间将插值渲染为模板语法
- css - 移除反应原生集合中选择器的边框
- android - 为什么 setInterval(,0) 使 NativeScript 中的动画更加流畅?
- c++ - 使用 dllimport 代替 dllexport