如何在Winforms中更改文本框边框的颜色和宽度? [英] How to change textbox border color and width in winforms?
问题描述
我想知道如何如下所示更改文本框的边框颜色和边框宽度
I would like to know how do I change the border color and border width of textbox as something shown below
如果是鼠标悬停,我需要显示一种颜色,而当鼠标按下时,我需要显示另一种颜色.
If it is mouse hover I need to display one colour and on mouse down I need to display another colour.
如果有的话,谁能向我解释详细过程.
Can anyone explain me the detailed process with the source if available.
推荐答案
您可以执行以下操作:
- 将
TextBox
放置在Panel
内 - 给面板填充1个像素
- 将文本停靠栏设置为
Fill
- 使文本框没有边框
然后,处理文本框中的鼠标事件,当鼠标进入/离开时,在两种颜色之间切换面板的背景颜色.
Then, handle mouse events on the text box, switch the background color of the panel between your two colors, when the mouse enters/leaves.
就使用资源/句柄而言,这不是最优雅的方法,但它无需任何自定义图形即可工作.
This isn't the most elegant approach in terms of using resources/handles but it should work without any custom drawing.
这篇关于如何在Winforms中更改文本框边框的颜色和宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!