如图中的自定义控件该如何实现呢?是comboBox还是ListView?
如图中的自定义控件该如何实现呢?是comboBox还是ListView?
[解决办法]
经过我多年windows程序开发经验,介个应该是 comboBox
[解决办法]
重写ComboBox控件吧。
下面是一个日期控件的列子,根据需要改一下。
public partial class ComboBoxEx : ComboBox
{
private ToolStripDropDown DateTool = new ToolStripDropDown();
private MonthCalendar M = new MonthCalendar();
private ToolStripControlHost ToolHost;
public ComboBoxEx()
{
this.DrawMode = DrawMode.OwnerDrawVariable;
M.DateSelected += new DateRangeEventHandler(M_SelectDay);
M.MaxSelectionCount = 1;
M.ShowTodayCircle = false;
InitTool();
}
public new int ItemHeight
{
get
{
return base.ItemHeight ;
}
set
{
base.ItemHeight = value;
this.Size = new Size(this.Size.Width, this.ItemHeight + 6);
}
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
//if (m.Msg != 123)
//{
//}
if (m.Msg == 0xf
[解决办法]
m.Msg == 0x133)
{
Graphics g = Graphics.FromHwnd(this.Handle);
g.DrawRectangle(new Pen(Color.White ,0), new Rectangle(this.ClientRectangle.Left, this.ClientRectangle.Top, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1));
g.Dispose();
}
if (m.Msg == 0x201)//在按下下拉按钮时
{
ShowDrop() ;
this.Focus() ;
return;
}
}
private void InitTool()
{
ToolHost = new ToolStripControlHost(M);
ToolHost.AutoSize = false;
ToolHost.Width = M.Width;
ToolHost.Height = M.Height;
DateTool.Items.Add(ToolHost);
}
private void ShowDrop()
{
try
{
M.TodayDate = DateTime.Parse(this.Text);
}
catch
{
M.TodayDate = DateTime.Now;
}
DateTool.Show(this, 0, this.Height);
}
private void M_SelectDay(object sender, DateRangeEventArgs e)
{
if (e.Start != null)
{
this.Text = e.Start.ToString("yyyy/MM/dd") ;
M.Invalidate();
DateTool.Hide();
}
}
}