0

I can do ref like

      private void videoSource_New( object sender, ref Bitmap image )

but how to call this "ref Bitmap image" inside button click event?

Hend Mourad
  • 55
  • 1
  • 8
  • https://stackoverflow.com/a/4756021/3286975 – z3nth10n Sep 04 '17 at 02:11
  • Inside the button click event ,simply refer to it, eg: `image.Load("...");`. What ever changes you make to the `image` variable in the button click will be passed back to the caller. – Jeremy Thompson Sep 04 '17 at 02:34
  • 1
    Why do you need to use `ref`? You need to show us a [mcve] for us to tell you how you should proceed - i.e. we need to see the full code relating to this handler signature in your question. – Enigmativity Sep 05 '17 at 02:02

1 Answers1

0

From wherever you are trying to call the function videoSource_New you simply need to use the ref keyword at the call site. I've shown a code snippet on how to call it from the button click event handler method of a windows forms application in C#:

public partial class Form1 : Form
{
    private void button1_Click(object sender, EventArgs e)
    {
        Bitmap myImage = LoadFromDisk();
        videoSource_New(sender,ref myImage);
    }

     private void videoSource_New( object sender, ref Bitmap image )
     {
         //some logic to make changes in image object or use the image object.
     }
}

Hope this helps!

RBT
  • 24,161
  • 21
  • 159
  • 240
  • Your code would have a syntax error on the call to `videoSource_New`. – Enigmativity Sep 05 '17 at 02:01
  • Thank you for pointing out the error. I've fixed the code snippet now. – RBT Sep 05 '17 at 02:54
  • Thanks for that. It would be useful for the OP to provide a reason to pass the image as `ref`. In your code, as it currently stands, there's no point. The `myImage` doesn't need to be updated back in the calling code so the call by `ref` is moot. – Enigmativity Sep 05 '17 at 07:58