c# - 去除左右边框

标签 c# winforms textbox

我希望我的 TextBox 看起来像这样
enter image description here

如何删除 TextBox 控件的左侧和右侧?

最佳答案

通常,您必须覆盖 OnPaint 事件才能执行此操作,但是对于文本框,这将不起作用,因为不会调用 OnPaint。

一种方法是将 TextBox 子类化,如 here 所述

但是我根本不建议你这样做,这对我来说听起来像是一项艰巨的任务(我自己从来没有这样做过),尤其是当你刚接触编程时。

也许只在 TextBox 上方或下方画一条线就足够了?

-编辑-

也许这会更好地解释它:

The TextBox is special in that you can't custom paint it. If you just want a custom border, you can create a new UserControl and add a TextBox with border style set to None. Make sure you leave enough room around the outside of the TextBox for a border. Then paint the border on the UserControl surface. An alternative method would be to handle the WM_NCPAINT message of the TextBox and paint the border then, but that is significantly more complicated.

来源:msdn 论坛中的 shawn.ohern:here (对不起,我不知道如何直接链接到他的帖子)

-edit2-link展示了一种创建您自己的 TextBox 的方法,同样,我不会向刚接触 c# 和编程的人推荐这种方法 ;)

关于c# - 去除左右边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15543522/

相关文章:

c# - 运行多个异步任务并等待它们全部完成

c# - 具有 beginwait 函数的信号量

c# - 并行运行测试和切换 iframe 时如何防止测试失败?

.net - 开源 Windows 窗体应用程序的建议控件?

c# - 我怎样才能通过键绑定(bind)在 xaml 中聚焦文本框?

c# - Entity Framework 6 FluentApi 一对一关系配置

winforms - 如何在Windows窗体应用程序中嵌入SQLite?

vb.net - 工具条按钮 = "Pressed"

javascript - 如何验证 html 文本框不允许特殊字符和空格?

c# - wpf 中的文本框验证