DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: cannot convert from 'System::Windows::Forms::Form^ to 'MyApplication::Form1 ^'

  1. #1
    Join Date
    Apr 2011
    Posts
    20

    cannot convert from 'System::Windows::Forms::Form^ to 'MyApplication::Form1 ^'

    Hi guys,

    I am working on my application as I am trying to create a code as public testmycode() function to linking up with the code that I have input them for each line in the form2_load event, so in that way it would make it shorter and it will be much easy for me to read the code in each line, but I can't be able to get rid of the error I am getting. No one would know how to help me and most of them don't know what I am trying to do, so I hope one of you will know what to do and how to help me out. I have stored the code in the form2.cpp.

    The error I am getting is: error C2440: 'initializing' : cannot convert from 'System::Windows::Forms::Form ^' to 'MyApplication::Form1 ^'


    The error are jumping on this line:

    Code:
    Form1^ form1 = form1->Owner;

    Here's the current code:

    Code:
    #include "StdAfx.h"
    #include "Form2.h"
    #include "Form1.h"
    
    using namespace System::Windows::Forms;
    
    using namespace MyApplication;
    
    
    Object ^testmycode()
    {
    	try
    	{
    		Form1^ form1 = form1->Owner;
    		//Address of URL
    		String ^URL = "http://www.mysite.com/myscript.php?user=" + form1->label1->Text + "&pass=" + form1->label2->Text;
    		HttpWebRequest ^request = safe_cast<HttpWebRequest^>(WebRequest::Create(URL));
    		HttpWebResponse ^response = safe_cast<HttpWebResponse^>(request->GetResponse());
    		StreamReader ^reader = gcnew StreamReader(response->GetResponseStream());
    		String ^str = reader->ReadToEnd();
    
    
            Form2^ form2 = gcnew Form2();
    		if (str->Contains(form2->TextBox1->Text))
    		{
    			//Let Start the timer
    			form2->timer1->Interval = 1000;
    			form2->timer1->Enabled = true;
    		}
    		else
    		{
    			form2->Label2->Visible = true;
    		}
    	}
    	catch (Exception ^ex)
    	{
    
    	}
    return nullptr;
    }
    
    
    System::Void Form2::Form2_Load(System::Object^  sender, System::EventArgs^  e) 
    {
    
        Form1 ^form1 = dynamic_cast<Form1 ^>(Owner);
    	if (form1->Menuitems1->Checked == true)
    	{
                testmycode();
            }
    	if (form1->Menuitems2->Checked == true)
    	{
                testmycode();
            }
    	if (form1->Menuitems3->Checked == true)
    	{
                testmycode();
            }
    	if (form1->Menuitems4->Checked == true)
    	{
                testmycode();
            }
    	if (form1->Menuitems5->Checked == true)
    	{
                testmycode();
            }
    }

    I have also tried this:

    Code:
    Form1 ^form1 = dynamic_cast<Form1 ^>(Owner);

    I have got an error: error C2065: 'Owner' : undeclared identifier.


    I don't know what I suppose to do so.

    Any help would be much appreicated.

    Thanks,
    Mark
    Last edited by mark108; 06-18-2011 at 01:41 PM.

Similar Threads

  1. how to convert binary string to int?
    By bob2000 in forum Java
    Replies: 4
    Last Post: 03-21-2007, 09:50 AM
  2. Convert a Char into HammingCode
    By fastmike in forum Java
    Replies: 1
    Last Post: 09-22-2006, 05:37 PM
  3. convert String to Calendar
    By Force Flow in forum Java
    Replies: 4
    Last Post: 06-29-2006, 01:01 PM
  4. Convert WAV in MP3
    By satoshi in forum Java
    Replies: 0
    Last Post: 03-31-2006, 07:58 AM
  5. SQL syntax error
    By Ted Young in forum Database
    Replies: 7
    Last Post: 08-07-2001, 03:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center