
03-Mar-2008, 12:04
|
|
Regular Member
|
|
Join Date: Oct 2007
Posts: 440
|
|
|
CreateParams does not exist in namespace
I'm trying to create a virtual list control in C# like the example here, but I keep getting this build error:
Code:
The type or namespace name 'CreateParams' does not exist in the namespace 'System.Windows.Forms' (are you missing an assembly reference?)
Here is the code:
C-SHARP / C# Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace PocketPCTest
{
public partial class VirtualListBox : ListBox
{
/*
* Listbox Styles
*/
private const int LBS_NOTIFY = 0x0001;
private const int LBS_SORT = 0x0002;
private const int LBS_NOREDRAW = 0x0004;
private const int LBS_MULTIPLESEL = 0x0008;
private const int LBS_OWNERDRAWFIXED = 0x0010;
private const int LBS_OWNERDRAWVARIABLE = 0x0020;
private const int LBS_HASSTRINGS = 0x0040;
private const int LBS_USETABSTOPS = 0x0080;
private const int LBS_NOINTEGRALHEIGHT = 0x0100;
private const int LBS_MULTICOLUMN = 0x0200;
private const int LBS_WANTKEYBOARDINPUT = 0x0400;
private const int LBS_EXTENDEDSEL = 0x0800;
private const int LBS_DISABLENOSCROLL = 0x1000;
private const int LBS_NODATA = 0x2000;
private const int LB_GETCOUNT = 0x018B;
private const int LB_SETCOUNT = 0x01A7;
public VirtualListBox()
{
InitializeComponent();
}
/// <summary>
/// Sets up the <see cref="CreateParams" /> object to tell
/// Windows how the ListBox control should be created. In
/// this instance the default configuration is modified to
/// remove <c>LBS_HASSTRINGS</c> and <c>LBS_SORT</c>
/// styles and to add <c>LBS_NODATA</c>and LBS_OWNERDRAWFIXED
/// styles. This converts the ListBox into a Virtual ListBox.
/// </summary>
protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
CreateParams defParams = base.CreateParams;
defParams.Style = defParams.Style & ~LBS_HASSTRINGS;
defParams.Style = defParams.Style & ~LBS_SORT;
defParams.Style = defParams.Style |
LBS_OWNERDRAWFIXED | LBS_NODATA;
return defParams;
}
}
[DllImport("user32", CharSet = CharSet.Auto)]
private extern static int SendMessage(
IntPtr hWnd, int msg, int wParam, IntPtr lParam);
/// <summary>
/// Gets or sets the number of virtual items in the ListBox.
/// </summary>
public int Count
{
get
{
return SendMessage(this.Handle,
LB_GETCOUNT, 0, IntPtr.Zero);
}
set
{
SendMessage(this.Handle,
LB_SETCOUNT, value, IntPtr.Zero);
}
}
/// <summary>
/// Throws an exception. All the items for a Virtual ListBox
/// are externally managed.
/// </summary>
/// <remarks>The selected index can be obtained using
/// the <see cref="SelectedIndex"/> and
/// <see cref="SelectedIndices"/> properties.
/// </remarks>
[BrowsableAttribute(false)]
public new SelectedObjectCollection SelectedItems
{
get
{
throw new InvalidOperationException("A Virtual ListBox does not have a SelectedObject collection");
}
}
/// <summary>
/// Gets/sets the selected index in the control. If the
/// control has the multi-select style, then the first
/// selected item is returned.
/// </summary>
public new int SelectedIndex
{
get
{
int selIndex = -1;
if (SelectionMode == SelectionMode.One)
{
selIndex = SendMessage(this.Handle,
LB_GETCURSEL, 0, IntPtr.Zero);
}
else if ((SelectionMode == SelectionMode.MultiExtended) ||
(SelectionMode == SelectionMode.MultiSimple))
{
int selCount = SendMessage(this.Handle,
LB_GETSELCOUNT, 0, IntPtr.Zero);
if (selCount > 0)
{
IntPtr buf = Marshal.AllocCoTaskMem(4);
SendMessage(this.Handle, LB_GETSELITEMS, 1, buf);
selIndex = Marshal.ReadInt32(buf);
Marshal.FreeCoTaskMem(buf);
}
}
return selIndex;
}
set
{
if (SelectionMode == SelectionMode.One)
{
SendMessage(this.Handle,
LB_SETCURSEL, value, IntPtr.Zero);
}
else if ((SelectionMode == SelectionMode.MultiExtended) ||
(SelectionMode == SelectionMode.MultiSimple))
{
// clear any existing selection:
SendMessage(this.Handle, LB_SETSEL, 0, new IntPtr(-1));
// set the requested selection
SendMessage(this.Handle, LB_SETSEL, 1, (IntPtr) value);
}
}
}
}
}
NOTE: This is for a PocketPC app...maybe that is the problem????
Does anyone have any ideas?
|