views:

117

answers:

2

i want to use the listview flicker"less" control found here http://geekswithblogs.net/CPound/archive/2006/02/27/70834.aspx

directly in my c# Project. i dont want to make a custom user control project, build it to dll and then import it in my project. i just want this all in my c# Programm i am making.

i think i have to add in my project a class, and add the code, but how can i use the control now directly in my project?

A: 

Open a toolbox in your visual studio project. Then click 'choose items'. Click browse, and select an assembly, which contains a control. Now you can use a control within a designer. Hope that is what you are asking about.

n535
please attend this :i dont want to make a custom user control project, build it to dll and then import it in my project ..i just want this all in my c# Programm iam making..
masoud ramezani
If this control is not distributed as a separate assembly, than you have to somehow build it.You don't have to make a separate project for that, just use the code in your existing project, i don't really see the problem...
n535
+1  A: 

In Visual Studio, right-click on your project and then click ADD | USER CONTROL. Name the new control ListViewNF and click ADD.

View the code for the new class. Change this line:

public partial class ListViewNF : UserControl

to this:

public partial class ListViewNF : ListView

and Rebuild. You'll get a compiler error about AutoScaleMode - just delete the line in InitializeComponent that's causing the error:

// delete this line:
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

So far, your code will look like this:

public partial class ListViewNF : ListView 
{ 
    public ListViewNF() 
    {
        InitializeComponent();
    }
}

Change it to this:

public partial class ListViewNF : ListView
{
    public ListViewNF()
    {
        InitializeComponent();

        //Activate double buffering
        this.SetStyle(ControlStyles.OptimizedDoubleBuffer | 
            ControlStyles.AllPaintingInWmPaint, true);

        //Enable the OnNotifyMessage event so we get a chance to filter out 
        // Windows messages before they get to the form's WndProc
        this.SetStyle(ControlStyles.EnableNotifyMessage, true);
    }

    protected override void OnNotifyMessage(Message m)
    {
        //Filter out the WM_ERASEBKGND message
        if (m.Msg != 0x14)
        {
            base.OnNotifyMessage(m);
        }
    }

}

Rebuild your project, and you should now see the ListViewNF in your Toolbox of controls on the left (right at the top). You can drag this control onto a form in the designer, just like a regular ListView.

MusiGenesis
Hi ...thanks ..that is exactly what i was looking for ..(i didnt knew that the control will be listed on the top of the list, it was there but i didnt see it !!!!!!!)thanks anyway to you all ..i also tried the option with adding it directly into code, and creating instance, and it works toooothanks all
PEEK