TextBox Control Transparency / Picturebox Text

心不动则不痛 提交于 2019-12-13 05:07:45

问题


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:


  1. Add a class

  2. 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

  1. Run your application

  2. go to tool box, at the top you should see an item called "TransparentTextBox" add that, ignore the error

  3. run app

  4. enjoy



来源:https://stackoverflow.com/questions/18580767/textbox-control-transparency-picturebox-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!