Control.Invoke with input Parameters

后端 未结 8 588
时光说笑
时光说笑 2020-12-08 05:24

From what I\'ve found in C#, the Control.Invoke method requires that you use a delegate with no input parameters. Is there any way around this? I would like to invoke a me

相关标签:
8条回答
  • 2020-12-08 06:16

    As Luke says, use Control.Invoke like this...

    For example in a form:

    public delegate void DelegatePassMessages(string name, int value);
    
    public DelegatePassMessages passMessage;
    

    In the contructor:

    passMessage = new DelegatePassMessages (this.MessagesIn);
    

    Then the MessagesIn function to receive data:

    public void MessagesIn(string name, int value)
    {
    
    }
    

    Then to pass data to your form:

    formName.Invoke(formName.passMessage, new Object[] { param1, param2});
    
    0 讨论(0)
  • 2020-12-08 06:16
        private void ppTrace(string tv)
        {
            if (_Txb1.InvokeRequired)
            {
                _Txb1.Invoke((Action<string>)ppTrace, tv);
            }
            else
            {
                _Txb1.AppendText(tv + Environment.NewLine);
            }
        }
    
    0 讨论(0)
提交回复
热议问题