在winform中通过form初始化后的名字.invoke可以往主界面控件上抛出东西, 
可是在做控件的时候,发现只有在调用控件的时候才会初始化,名字就没有办法知道,invoke语句也就没法写了 
请问各位大大有什么办法没有呢?比较急:)

解决方案 »

  1.   

    问题有些不清楚啊你是要在控件里访问,form 上的其他控件???
    否则1楼对了!哈哈
      

  2.   

    不是啊,线程是要写在在控件里定义的另外一个类里,每次要用的时候在控件的主线程里new  出来, 分别访问这个自己做的控件上的几个控件.this.invoke做不到吧
      

  3.   

    实际上我就是public UserControl1.VedioAdd mVedioAdd = new UserControl1.VedioAdd(UserControl1.InsertPicture);在红字这里不知道怎么写了
      

  4.   

     InsertPicture是在我的控件主程里的一个写界面的函数,如下,
    VedioAdd是自定义的委托,怎么把控件主线程里的方法挂上的问题,
    不是做控件,而是直接写winform的时候比较简单,在Program里面Application.Run();以前自定义一个静态主窗体来run就可以了,
    比如Form1 mMainForm =new Form1();
    Application.Run(mMainForm);
    然后我委托只要挂
    public   mMainForm.VedioAdd   mVedioAdd   =   new   mMainForm.VedioAdd(mMainForm.InsertPicture);
    可是在一个如果要在叫UserControl1的控件里面做同样的就没有办法做相同的操作了,那我该怎么做呢?public delegate void VedioAdd(byte[] DecodedPicture, int ScreenIndex);
    public void InsertPicture(byte[] DecodedPicture,int ScreenIndex)
            {            DateTime CurrentTime = DateTime.Now;
                if (this.pictureBoxGroup [ScreenIndex ].InvokeRequired)
                {
                    //OutDelegate d = new OutDelegate(OutEventLog);
                    this.BeginInvoke(new VedioAdd(InsertPicture), DecodedPicture,ScreenIndex );
                }
                else
                {
                    Monitor.Enter(this.pictureBoxGroup[ScreenIndex]);
                    //if (OutLog.Items.Count > 2)                //      OutLog.Clear(); 
                    try
                    {
                        MemoryStream PictureStream = new MemoryStream(DecodedPicture);
                        Graphics g = this.pictureBoxGroup[ScreenIndex].CreateGraphics();
                        g.DrawImage(Image.FromStream(PictureStream), new Rectangle(0, 0, this.pictureBoxGroup[ScreenIndex].Size.Width, this.pictureBoxGroup[ScreenIndex].Size.Height));
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                        g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
                        //System.Threading.Thread.Sleep(60);
                        PictureStream.Close();
                    }
                    catch (System.ObjectDisposedException)
                    {
                        this.pictureBoxGroup[ScreenIndex].Dispose();
                    }
                    //pictureBoxGroup[PlayingBoxVedioIndex]//.Items.Add(CurrentTime.Date.ToShortDateString() + " " + CurrentTime.ToLongTimeString() + " " + text, IconFlag);
                    Monitor.Exit(this.pictureBoxGroup[ScreenIndex]);
                }        }