日期:2014-05-20  浏览次数:20729 次

【提问】为什么自定义控件中重载的事件无法响应,请看代码
这个是自定义控件中的代码。

    public partial class PicListEx : UserControl
    {
        private Size size = new Size(100, 100);

        private Thread LoadPictureThread = null;

        public PicListEx()
        {
            InitializeComponent();
            lViewPic.View = View.LargeIcon;
        }

        /// <summary>
        /// 加载图片
        /// </summary>
        /// <param name="filePaths">包含图片路径的数组</param>
        public void loadPicFile(List<string> filePaths)
        {
            if (LoadPictureThread == null || !LoadPictureThread.IsAlive)
            {
                LoadPictureThread = new Thread(new ParameterizedThreadStart(LoadPictureFunc));
                LoadPictureThread.IsBackground = true;
                LoadPictureThread.Start(filePaths);
            }
            else
            {
                return;
            }
        }

        private void LoadPictureFunc(object obj)
        {
            List<string> filePaths = null;
            if (obj is List<string>)
            {
                filePaths = obj as List<string>;
            }
            else
            {
                return;
            }
            try
            {
                Invoke(new MethodInvoker(new Action(delegate()
                {