在WinForms应用程序中,我正在尝试创建Native Win32 ListBox。我确实有这样一个最小的代码,它创建了控件,但ListBox的背景不是白色,也没有垂直滚动条。
public partial class NativeListBox : Form
{
public NativeListBox()
{
InitializeComponent();
}
private void NativeListBox_Load(object sender, EventArgs e)
{
ListBoxEx lb = new ListBoxEx
{
Style = 1345523968,
ExStyle = 512,
Top = 10,
Left = 10,
Width = 220,
Height = 300
};
Controls.Add(lb);
}
}
public class ListBoxEx : Control
{
public int Style { get; set; }
public int ExStyle { get; set; }
protected override CreateParams CreateParams
{
get
{
var cp = base.CreateParams;
cp.ClassName = "LISTBOX";
//cp.Style |= Style;
//cp.ExStyle |= ExStyle;
cp.Style |= NativeMethods.WS_VSCROLL | NativeMethods.LBS_NOTIFY | NativeMethods.LBS_HASSTRINGS | NativeMethods.WS_BORDER;
return cp;
}
}
}
看起来缺少某些东西。我从.NET https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/ListBox.cs,03c7f20ed985c1fc检查了这个源代码,但没有注意到在最小化身中创建ListBox的其他任何特殊内容。
任何想法还应该添加什么?
由于其他一些技术难题,我无法使用.NET本身的Standard ListBox。