Transparent LISTVIEW

.NET is the packaging is too thick, sometimes a lot of time for us but more trouble, especially COPY less than when they do not know their own wish to do so, saying that the soil is a dead end,

Always remember one sentence, C ++ support, he does not C # support ah! It was so comforting himself

In fact, do more to understand, in fact, not C # does not support, but do not understand their own, not that the procedures that nothing is impossible, but you do not find a way to it, language is only coat, inherent is the same,

JAVA configuration environment variable as a reason, if not touched C # people to touch the installed environment variables will keep hammering JAVA development environment, but sometimes their own hands to install so what, was able to learn a lot


In fact, one thing is clear LISTVIEW very EASY friends

But .NET does not provide set the background, or did not provide background tile stretch, is a pull-down box, the picture will also follow the move, can not be saved

It has been very soil, a move I brush background, painting or system, even gave him an extra double-buffering, TNND there are obvious lag

I want to do this effect

Bottom line: not to repaint it!

 

Of course, this figure not completely put out, or a humble form! Haha

And after effects after redrawing is below this myself

 


Hey! Colleagues also gave some of the information displayed, sorry ah!

The following began to introduce redrawn

First, this control must be transparent, and transparent on the premise that this control is self repaint

this.SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true);
this.SetStyle(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;

The definition of these properties is crystal clear ah! Has thus see, a good name for a program, it is important how much ah! We use is really quite cool at a glance

Start redrawing myself
protected the override void OnPaintBackground (PaintEventArgs pevent)
{
// allow the system to choose their own painting background, it is actually useless
base.OnPaintBackground (pevent);

if (TopItem == null || ListViewImageList.Images.Count == 0)
{
return;
}
// Videos to several
int = Curin is This.Height / 18 is +. 1;
// only the first non-empty Videos
if ( TopItem! = null && TopItem.Index> = 0)
{
IF (CurSelectIndex CurSelectIndex == -1 || <|| CurSelectIndex TopItem.Index> (+ This.Height TopItem.Index / 20 is))
{

}
The else
{
/ the currently selected item
int i = CurSelectIndex - TopItem.Index;
that is, draw a rectangle that you, the chosen place, forgot to say, I set high as 18 like cable
pevent.Graphics.FillRectangle (Brushes.AliceBlue, 0 , 18 is I *, 300, 18 is);
}
then is draw down one by one
for (int I = 0; I <Curin is; I ++)
{
IF ((TopItem.Index + I) <this.Items.Count)
{
IF (this.items [TopItem.Index + I] .ImageIndex <ListViewImageList.Images.Count)
{
pevent.Graphics.DrawImage (ListViewImageList.Images [this.items [TopItem.Index + I] .ImageIndex], 0, I * 18 + 1);

; pevent.Graphics.DrawString (this.items [TopItem.Index + I] .Text, this.Font, Brushes.Black, 30, 18 is + I *. 1)
}
! down first from the first control is very simple began to draw, that is, the control can display twenty, no matter how many items of data there, it drew only twenty, high efficiency it! even have saved the double buffer
}
}
}
}


Then it is the pull-down! Under Larry refreshed Well! TNND event can provide him with treatment there is no message processing drop-down box, because this is not a tree control

But we still have a way, the message is pulled down inside the WINDOWS: m.Msg == 0x114 || m.Msg == 0x115

This is where a little WIN API to the experienced people know

In it catch them a bit, and then send out commission, this time a good name appeared, people still do not understand is that .NET provides that the use of indiscriminate cool it, ha ha

protected override void WndProc(ref Message m)
{
if (m.Msg == 0x114 || m.Msg == 0x115)
{
if (OnScroll != null)
{
OnScroll(this, m.Msg == 0x115);
}
}
}

When the mouse to slide in health as well as the drop-down shift to redraw, and soon, on that twenty only thing!
Protected the override void OnMouseWheel (MouseEventArgs E)
{
base.OnMouseWheel (E);
this.Invalidate ();
}

DouBufferListview_OnScroll void (Object SENDER, BOOL VScroll)
{
this.Invalidate ();
}
selected in the effect on the left click it, behind the front will not bother COPY code, ha, or brush,

 

Is actually very simple, the most important is the three aspects of
one: a transparent background
Two: is completed in OnPaintBackground, because userpaint set TRUE, this function is the final step in a system call, before painting, you painted half to death, are covered
three: it is to catch them messages, WINPROC this understanding on the line

 

This is absolutely original, but also the pain of their own for a few days, almost giving up, suddenly thought ONPAINTGROUND function in the New Year's Day, deliberately overtime try out, free Oh! Hey!'Ve never actually been working overtime took overtime, see the other students have to work overtime, it really was great! unhappy but unhappy return, things still have to do a good job

In fact, we are young, from the beginning, gradually realized that stuff does not fail to realize that only you can not do stuff, I just want to focus on WINFORM, everything slowly

Alone came here on their own has always been a gamble, in fact, want to go to complete that degree,

Unfortunately, a few months ago I did not think so, that this college acceptance letter to throw at home and ran out!

Young is the impulse, but the young is the courage to pay! I believe in yourself

 

Then another day that group of cute button to put out what shape you what shape would like oh! Very kawaii Oh!

Guess you like

Origin www.cnblogs.com/blogpro/p/11460089.html