如果填充当前行宽,WinForm会自动换行 [英] WinForm wrap text if current row width is filled

查看:157
本文介绍了如果填充当前行宽,WinForm会自动换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WinForm中有DataGridView。我将 AutoSizeColumnsMode 设置为 Fill ,因为如果用户调整窗口大小,则不需要空格。

I have DataGridView inside my WinForm. I set AutoSizeColumnsMode to Fill, because I need no white space if user resizes the window.

我想要实现的目标。例如,用户在特定单元格中键入一些文本。当文本宽度变为单元格宽度时,文本必须换行。

可能是这样的:

What I want to achieve. For example, user types some text in the certain cell. When text width becomes as cell width, text must go one the new line.
How it might be:

|Cell Header|
-------------
|text-text  |

|Cell Header|
-------------
|text-text  |
|more text  |
|on the new |
|line       |

我的列可以按用户调整大小。因此:

My columns are resizable by user. So this:

|Cell Header|
-------------
|text-text  |
|more text  |
|on the new |
|line       |

可能会这样做:

|Cell Header        |
---------------------
|text-text more text|
|on the new line    |

我从其他方法得到的答案:

What I have tried from other SO answers:


  • AutoResizeRowsMo​​de 设置为 AllCells -没有帮助

  • DefaultCellStyle.WrapMode 设置为 True -不会帮助

  • set AutoResizeRowsMode to AllCells - didn't help
  • set DefaultCellStyle.WrapMode to True - ddin't help

我实际上如何实现?

编辑:列设置:

编辑#2:


推荐答案

设置 RowsDefaultCellStyle.Wrapm ode = true 而不是 DefaultCellStyle.WrapMode = true

我对两个网格都使用了默认设置。这是我的设置:

I used default settings for both of the grid. This is my settings :

这是代码

这篇关于如果填充当前行宽,WinForm会自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆