简体   繁体   English

VB.Net/C#-Listview网格线

[英]VB.Net/C# - Listview Gridlines

How can I show only vertical Gridlines in my Listview, without horizontal gridlines? 如何在列表视图中仅显示垂直网格线而没有水平网格线? Like for example in taskmanager? 例如在taskmanager中? Is there a way to do this with GDI? 有没有办法用GDI做到这一点? I am not sure how I can realize that, every helpful comment is appreciated :) 我不确定如何实现这一点,每条有用的评论都会受到赞赏:)

When you and I create controls we usually overload the onPaint method and do all our drawing there. 当您和我创建控件时,我们通常会重载onPaint方法并在那里进行所有绘制。 Most of the default controls that you find in the toolbox however, redraws certain parts at certain messages, which makes it hard to draw over them as you never know when the control will redraw. 但是,您在工具箱中找到的大多数默认控件都会在某些消息上重画某些部分,这使您难以绘制它们,因为您永远不知道控件何时会重画。 It is possible to do so however, and the only way to figure out when to draw is by trail and error. 但是,这样做是可行的,而找出何时绘制的唯一方法是走错路。

If you're lucky it's enough to redraw at a couple of events, but, for the most part overloading the WndProc method is the way to go. 如果幸运的话,在几个事件中重绘就足够了,但是在大多数情况下,重载WndProc方法是可行的方法。

I'm currently on a windows 8 computer, where the grid lines aren't drawn at all, so it's kinda hard to write a good example of how to remove the horizontal ones, but I'd just paint over them with the background color and then draw the vertical ones afterwards. 我目前在Windows 8计算机上,根本没有画出网格线,因此很难写出一个很好的示例来删除水平线,但是我只是用背景色覆盖它们然后画垂直的 The code below draws horizontal grid lines: 下面的代码绘制水平网格线:

Public Class MyListView
Inherits ListView

Private Sub DrawLines() Handles Me.MouseUp
    Dim G = CreateGraphics()
    Dim x As Integer

    For i = 0 To Columns.Count - 1
        x += Columns(i).Width
        G.DrawLine(New Pen(Color.FromArgb(230, 230, 230)), x, 0, x, Height)
    Next
End Sub

Protected Overrides Sub WndProc(ByRef m As Message)
    MyBase.WndProc(m) ' To prevent something from drawing you can simply not do this call at a specific message
End Sub

End Class

A list of windows messages Windows消息列表

Spy++ can also be helpful to find the right messages 间谍++也可能有助于找到正确的消息

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

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