简体   繁体   English

在Winform应用程序中从GUI更改列宽时的文本对齐

[英]Alignment of text when column width is changed from GUI in winform application

I have developed a winform application. 我已经开发了一个Winform应用程序。 It has a listview with multiple columns having different texts. 它具有一个列表视图,其中多个列具有不同的文本。 Initially, I have set the column width = -2 to take the size of longest text in the column. 最初,我将列宽设置为-2以获取列中最长文本的大小。

The issue is that sometime text overshoots the laptop screen and a horizontal scroll bar appeared in the list view. 问题在于,有时文本会超出笔记本电脑的屏幕,并且列表视图中会出现水平滚动条。

To fit all the columns in a screen, I manually modified the columns widths using column boundaries in the GUI. 为了适合屏幕中的所有列,我在GUI中使用列边界手动修改了列宽。 When I modify the column width, the column text starts disappearing from right. 当我修改列宽时,列文本开始从右侧消失。 I want it to disappeared from left. 我希望它从左边消失。

I have searched goggle a lot but did not find the answer. 我搜索过很多护目镜,但没有找到答案。

Question might look weird or may be I have not explained it properly. 问题可能看起来很奇怪,或者可能是我没有正确解释。 Please let me know if more information is needed. 请让我知道是否需要更多信息。

Thanks in advance. 提前致谢。

The Listbox columns in Windows Forms are not exactly a high level control, I've used it some times but just for simple lists, It certainly has not a builtin function to make what you want, to obtain it you probably need to subclass the control, create a new class for the item managed in the list and write some code to perform what you need. Windows窗体中的“列表框”列并不完全是一个高级控件,我已经使用过几次,但仅用于简单列表,它当然没有内置函数可以实现所需功能,要获取该控件,您可能需要将其子类化,为列表中管理的项目创建一个新类,并编写一些代码来执行所需的操作。 I think you can find some hints on how to achieve all this in Charles Petzold book about windows forms where he shows how to measure a string and how to draw directly on your control. 我认为您可以在Charles Petzold的有关Windows窗体的书中找到有关如何实现所有这些功能的一些提示,其中他展示了如何测量字符串以及如何直接在控件上绘制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM