• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

Accessing a public void from newly opened window.

So i'm attempting to have a public void accessible from a newly opened window.  I know that  if I use example 1 on the code sheet that I can pass a string to the new window. But I would like to pass the void to the new window kinda like also passing a htmlelement using the same method.

So a short question format, how do I pass a void to a new window?

Thanks :)
Example 1:

Form commitmentwall = new commitmenttime("");
commitmentwall.Show(); 

public commitmenttime(string text)

Open in new window

0
Jakelee80
Asked:
Jakelee80
  • 5
  • 5
  • 2
1 Solution
 
magicdlfCommented:
Use object as parameters. For example

public commitmenttime(object obj)
0
 
magicdlfCommented:
0
 
Jakelee80Author Commented:
Ok so I got "public commitmenttime(object commitmentpass)" setup but the link your referanced I couldent find anything for passing the method. Would you have a small example? Like converting the method to an object to then pass over? Thanks again :)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
magicdlfCommented:
Try this:
0
 
magicdlfCommented:
       public Form2(object content)
        {
            InitializeComponent();
            if (content as string != null)
            {
                //display string
            }
            else if (content as HtmlElement !=null)
            {
                //display htmlelment
            }
        }

In main form:
        private void button1_Click(object sender, EventArgs e)
        {
            Form2 form = new Form2("string");
            form.Show();
        }
0
 
Jakelee80Author Commented:
Oh I think it was interpreted wrong but thanks for the example, I see the main form sending a string to the form2, what I mean is how would you have the main form send a method to form2 to then have form2 send a string back to the main form. Sorry about the confusion. Thanks again for your assistance.
0
 
ThejakaCommented:
Did you try my link above? It points to some info on delegates which can be used to pass a method along as a parameter.

For your problem, it would be simpler to use a ref argument.
http://msdn.microsoft.com/en-us/library/14akc2c7.aspx
0
 
magicdlfCommented:
Oh, then you need to use delegate.
    public partial class Form2 : Form
    {
        public delegate string StringDelegate();

        public StringDelegate StringEvent = null;
        public Form2()
        {
            InitializeComponent();

        }

        private void Form2_Load(object sender, EventArgs e)
        {
            if (StringEvent != null)
            {
                //get the message from the event;
                string str = StringEvent();
                MessageBox.Show(str);
            }
        }

    }



    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        String doSomething()
        {
            return "hello";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 form = new Form2();
            form.StringEvent = doSomething;
            form.Show();
        }

    }
0
 
Jakelee80Author Commented:
Was kind and helpful. Big thanks.
0
 
Jakelee80Author Commented:
That looks like it works as I needed it. :) Thanks for your assistance, have a wonderful holiday :)
0
 
Jakelee80Author Commented:
Thejaka: I reviewed it and tested some combination's of it but had troubles understanding the flow of it, will keep it for reference though, Thanks. Heh should have selected multiple solution since there were 2 helping referencing the same thing.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now