CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2003
    Location
    Moscow, Russia
    Posts
    3

    How to use Windows Forms in C++ project?

    Hi.
    Is System.Windows.Forms written only for C#?
    If it possible to use it in C++ projects, how to do this?

  2. #2
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    it is not the WinAPI question!!!

    However, yes it is possible, but only if you use managed c++...

  3. #3
    Join Date
    Jan 2003
    Location
    Moscow, Russia
    Posts
    3

    Using it in managed C++ project...

    OK.
    We have a managed C++ project.
    Connect to System.Windows.Forms
    #using <System.Windows.Forms>
    But this not enough!

    Something else ??

  4. #4
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    Why don't you use Search function? There are many examples of this on this site as well as on the others at the Internet!
    Code:
    #include "stdafx.h"
    
    #using <mscorlib.dll>
    #using <System.dll>
    #using <System.Drawing.dll>
    #using <System.Windows.Forms.dll>
    
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::&#68;rawing;
    using namespace System::Windows::Forms;
    
    __gc class MyForm : public Form
    {
    public:
        MyForm();	
    
        Label*  m_label;
        Button* m_button;
    
        void Button_OnClick(Object* sender, System::EventArgs* e);
    };
    
    MyForm::MyForm()
    {
        this->Text = "Windows Forms";
        this->FormBorderStyle = FormBorderStyle::FixedDialog;
        this->ClientSize = System::&#68;rawing::Size(500,500);
    
        m_label = new Label();
        m_label->Text="This is Label";
        m_label->Size = System::&#68;rawing::Size(200,20);
        m_label->Location=Point(10, 10);	
    
        m_button = new Button();
        m_button->Size = System::&#68;rawing::Size(80, 25);
        m_button->Location = Point(60, 35);
        m_button->Text = "Click me";
        m_button->add_Click(new EventHandler(this, &MyForm::Button_OnClick));
    
        this->Controls->Add(m_label);
        this->Controls->Add(m_button);
    }
    
    void MyForm::Button_OnClick(Object* sender, System::EventArgs* e)
    {
        MessageBox::Show("Don't click me again!", "Button");
    }
    
    int __stdcall WinMain()
    {
        Application::Run(new MyForm());
        return 0;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured