ListBox with overriden CreateParams doesn't raise item events

浪尽此生 提交于 2019-12-13 04:28:12

问题


I've created a custom ListBox like in here. Thing is it doesn't raise any of the item specific events like DrawItem and SelectedIndexChanged.

Any idea why? Thanks.


回答1:


It worked just fine when I tried this code:

  public partial class Form1 : Form {
    MyListBox mList;
    public Form1() {
      InitializeComponent();
    }

    protected override void OnLoad(EventArgs e) {
      mList = new MyListBox(this);
      mList.Location = new Point(5, 10);
      mList.Size = new Size(50, this.ClientSize.Height + 50);
      for (int ix = 0; ix < 100; ++ix) mList.Items.Add(ix);
      mList.SelectedIndexChanged += new EventHandler(mList_SelectedIndexChanged);
    }

    void mList_SelectedIndexChanged(object sender, EventArgs e) {
      MessageBox.Show(mList.SelectedIndex.ToString());
    }

    protected override void Dispose(bool disposing) {
      // Moved from Designer.cs file
      if (disposing) mList.Dispose();
      if (disposing && (components != null)) {
        components.Dispose();
      }
      base.Dispose(disposing);
    }

  }


来源:https://stackoverflow.com/questions/398176/listbox-with-overriden-createparams-doesnt-raise-item-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!