开发者

use custom control directly in Visual Studio project

i want to use the listview flicker"less" co开发者_JAVA百科ntrol 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜