问题
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.
Like this: http://puu.sh/4hzQM.png
This is how it looks like for me: 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
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.
Thanks.
回答1:
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
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
来源:https://stackoverflow.com/questions/18580767/textbox-control-transparency-picturebox-text