vb.net 文本框控件透明度/图片框文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18580767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TextBox Control Transparency / Picturebox Text
提问by codegenius
I have been wanted to create a custom text box and so I have found two methods which would allow me to achieve this although they aren't the best. One of the them is to actually draw text on the picturebox itself, but I wasn't able to find any tutorials or code to allow me to create this.
我一直想创建一个自定义文本框,所以我找到了两种方法,尽管它们不是最好的,但它们可以让我实现这一目标。其中之一是在图片框本身上实际绘制文本,但我找不到任何教程或代码来允许我创建它。
But I did find something for a Alpha channel textbox which although didn't allow me to put the control over other controls, I was able to work with it. The code works but my only problem now that is when other people use it the text is blurry.
但是我确实为 Alpha 通道文本框找到了一些东西,尽管它不允许我将控制权放在其他控件上,但我能够使用它。该代码有效,但我现在唯一的问题是当其他人使用它时,文本变得模糊。
Like this: http://puu.sh/4hzQM.png
像这样:http: //puu.sh/4hzQM.png
This is how it looks like for me: http://puu.sh/4hzUD.jpg
这就是我的样子:http: //puu.sh/4hzUD.jpg
I am currently using this code, which I converted to vb.net: http://www.codeproject.com/Articles/4390/AlphaBlendTextBox-A-transparent-translucent-textbo
我目前使用此代码,这是我转换成vb.net:http://www.codeproject.com/Articles/4390/AlphaBlendTextBox-A-transparent-translucent-textbo
I was wondering if there is a way to fix this blurry text on other computers or if there is an easier way of doing this, because that code is 10 years old and everywhere I search, I can't find anything else.
我想知道是否有办法在其他计算机上修复此模糊文本,或者是否有更简单的方法来执行此操作,因为该代码已有 10 年历史,而且在我搜索的任何地方,我都找不到其他任何内容。
Thanks.
谢谢。
回答by user3597926
Add a class
insert this:
添加班级
插入这个:
Class TransparentControl
Inherits Control
Public Sub New()
MyBase.SetStyle(ControlStyles.UserPaint, True)
MyBase.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
MyBase.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
MyBase.SetStyle(ControlStyles.ResizeRedraw, True)
MyBase.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
End Sub
End Class
Class TransparentTextBox
Inherits TextBox
Public Sub New()
MyBase.ScrollBars = RichTextBoxScrollBars.Both
End Sub
Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20
Return cp
End Get
End Property
Protected Overloads Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
MyBase.OnTextChanged(e)
MyBase.Parent.Refresh()
End Sub
End Class
Class TransparentControl
Inherits Control
Public Sub New()
MyBase.SetStyle(ControlStyles.UserPaint, True)
MyBase.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
MyBase.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
MyBase.SetStyle(ControlStyles.ResizeRedraw, True)
MyBase.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
End Sub
End Class
Class TransparentTextBox
Inherits TextBox
Public Sub New()
MyBase.ScrollBars = RichTextBoxScrollBars.Both
End Sub
Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20
Return cp
End Get
End Property
Protected Overloads Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
MyBase.OnTextChanged(e)
MyBase.Parent.Refresh()
End Sub
End Class
Run your application
go to tool box, at the top you should see an item called "TransparentTextBox" add that, ignore the error
run app
enjoy
运行您的应用程序
转到工具框,在顶部你应该看到一个名为“TransparentTextBox”的项目,添加它,忽略错误
运行应用
请享用

