如何从formload中绘制listview列和行? [英] How do I draw in listview columns and rows from formload?
问题描述
截至目前,我可以通过单独的活动进行此操作,
这里是我正在使用的代码:
<登记/>
as of now I am able to do this from a separate event,
here is the code I am using:
Private Sub ListView1_DrawSubItem(sender As Object, e As System.Windows.Forms.DrawListViewSubItemEventArgs) Handles ListView1.DrawSubItem
With e.Graphics
.DrawLines(New Pen(SystemColors.ButtonShadow), New Point() {New Point(e.Bounds.Left, e.Bounds.Top - 1), New Point(e.Bounds.Left + e.Bounds.Width, e.Bounds.Top - 1), New Point(e.Bounds.Left + e.Bounds.Width, e.Bounds.Top + e.Bounds.Height), New Point(e.Bounds.Left, e.Bounds.Top + e.Bounds.Height)})
End With
e.DrawText()
End Sub
我试图将其转移到form_load事件的原因是,每当我调用listview1.click事件时,listview会一直闪烁。但是,我相信这可能会停止,如果这是永久性地在listview上绘制而不是每次都被绘制它自己的事件。
我尝试过:
我尝试使用creategraphics
这里是我试过的代码:
The reason I am trying to get this over to the form_load event is that every time I call forth my listview1.click event the listview keeps flashing. However, I believe this may stop if this was drawn on listview permanently instead of being its own event being drawn every time.
What I have tried:
I tried using a creategraphics
here is the code I tried:
With CreateGraphics()
.DrawLines(New Pen(SystemColors.ButtonShadow), New Point() {New Point(ListView1.Bounds.Left, ListView1.Bounds.Top - 1), New Point(ListView1.Bounds.Left + ListView1.Bounds.Width, ListView1.Bounds.Top - 1), New Point(ListView1.Bounds.Left + ListView1.Bounds.Width, ListView1.Bounds.Top + ListView1.Bounds.Height), New Point(ListView1.Bounds.Left, ListView1.Bounds.Top + ListView1.Bounds.Height)})
End With
但它不起作用
but it didn't work
推荐答案
经过几天的搜索和尝试不同的事情,我找到了我正在寻找的解决方案。但是,我并不完全理解它是如何工作的,但它确实可以阻止闪烁。
After a couple days of searching and trying different things, I found the solution I was looking for. However, I do not completely understand how it works, but it does stop the flickering.
Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams 'stop flicker code part 1 of 2
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or 33554432
Return cp
End Get
End Property
Private Sub PreVentFlicker() 'stop flicker code part 2 of 2
With Me
.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
.SetStyle(ControlStyles.UserPaint, True)
.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
.UpdateStyles()
End With
End Sub
< br $> b $ b
http://www.dreamincode.net/forums/topic/294248-flicker-problem-on-form-loading/
http://www.dreamincode.net/forums/topic/294248-flicker-problem-on-form-loading/
这篇关于如何从formload中绘制listview列和行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!