日期:2014-05-18  浏览次数:20742 次

继承ComboBox控件的问题。写过控件的朋友进来看看
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace DataRelationAndConstraint
{
  class ComboBoxPlay : ComboBox
  {
  protected override void WndProc(ref Message m)
  {
  base.WndProc(ref m);
  if (m.Msg == 0x000F)
  Draw();
   
  }

  private void Draw()
  {
  Graphics gra = this.CreateGraphics();
  gra.DrawRectangle(Pens.Red, this.Bounds.X - 3, this.Bounds.Y - 3, this.Bounds.Width - 2, this.Bounds.Height - 2);
  }
  }
}
我想在控件上画一个红色的框,怎么画不出来呀?
本来想做一个颜色选择的ComboBox控件,类似于属性框里面BackgroudColor属性的颜色选择框,但现在连一个框都画不出来就别说实现更复杂的功能了。望高手指点。

------解决方案--------------------
应该重写 protected override void OnPaint(PaintEventArgs e) 吧

------解决方案--------------------
重写Combobox方法和属性
------解决方案--------------------
在codeproject.com找找。。

感觉思路不对。
------解决方案--------------------
学习学习呵
------解决方案--------------------
要重写ComboBox控件的OnPaint方法,在OnPaint方法中添加代码.