如何转换.h文件到win designer ... [英] How to convert a .h file to win designer file...

查看:65
本文介绍了如何转换.h文件到win designer ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我已使用转换工具将C#项目转换为CLI / C ++。然后工具在语法上将代码从C#转换为CLI / C ++。



工具转换&创建.h&各个.cs文件的.cpp文件。



但是,对于窗口形式&它创建的form.designer.cs文件.h& .cpp文件。

设计器代码放在InitializeComponent()函数的.cpp文件中。



C#窗口表单文件转换后的代码.cpp如下: -

文件名 - Form.cpp

Hello,

I have converted a C# project to CLI/C++ using a converter tool. Then tool has syntactically converted the code from C# to CLI/C++.

Tool converted & created .h & .cpp files for respective .cs files.

But, for window form & form.designer.cs file it has created .h & .cpp file.
The designer code is placed in .cpp file in InitializeComponent() function.

C# window form file converted code to .cpp is given below: -
File name - Form.cpp

#include "ToSeeGUIForm.Form.h"
using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Linq;
using namespace System::Text;
using namespace System::Windows::Forms;
namespace ToSeeGUIForm
{
    FormInCSharpProject::FormInCSharpProject()
    {
        InitializeComponent();
    }
    void FormInCSharpProject::DisposeObject(bool disposing)
    {
        if (disposing && (components != nullptr))
        {
            delete components;
        }
//C# TO C++ CONVERTER NOTE: There is no call to the base class's Dispose method in C++:
//      base.Dispose(disposing);
    }
    void FormInCSharpProject::InitializeComponent()
    {
        this->btnButton = gcnew System::Windows::Forms::Button();
        this->txtTextBox = gcnew System::Windows::Forms::TextBox();
        this->SuspendLayout();
        //
        // btnButton
        //
        this->btnButton->Location = System::Drawing::Point(110, 111);
        this->btnButton->Name = "btnButton";
        this->btnButton->Size = System::Drawing::Size(75, 23);
        this->btnButton->TabIndex = 0;
        this->btnButton->Text = "Button";
        this->btnButton->UseVisualStyleBackColor = true;
        //
        // txtTextBox
        //
        this->txtTextBox->Location = System::Drawing::Point(98, 71);
        this->txtTextBox->Name = "txtTextBox";
        this->txtTextBox->Size = System::Drawing::Size(100, 20);
        this->txtTextBox->TabIndex = 1;
        //
        // FormInCSharpProject
        //
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(292, 266);
        this->Controls->Add(this->txtTextBox);
        this->Controls->Add(this->btnButton);
        this->Name = "FormInCSharpProject";
        this->Text = "FormInCSharpProject";
        this->ResumeLayout(false);
        this->PerformLayout();
    }
}





由于这个CLI / C ++项目没有显示窗口形式(视图设计)文件对于.cpp文件。这使得gui难以改变。更改只能通过代码完成。



有选项,所以我可以更改.h& .cpp文件到窗口窗体文件?



谢谢

Kedar



Due to this CLI/C++ project is not showing window form (view design) file for the .cpp file. This makes difficult to change gui. Changes are to be done through code only.

Is there option so I can change the .h & .cpp file to window form file?

Thanks
Kedar

推荐答案

1- C#designer使用部分类:1个类被分成几个文件。在部分关键字的C ++ / CLI中没有等价物,所以你需要合并两个文件。



2-在C ++ / CLI你不应该使用处理终结者。有关更多详细信息,请参阅该链接:

http://msdn.microsoft.com /en-us/library/ms177197.aspx [ ^ ]



3-你真的需要转换项目吗?你不能只将C#程序集引用到C ++ / CLI项目中吗?实际上并不建议在C ++ / CLI中处理WinForms ...
1- C# designer uses partial classes: 1 class is splitted into several files. There is no equivalent in C++/CLI for the partial keyword, so you need to merge both files.

2- in C++/CLI you shouldn't use Dispose but Finalizers. See that link for more details:
http://msdn.microsoft.com/en-us/library/ms177197.aspx[^]

3- Do you really need to convert the project? Can't you just reference the C# assembly into your C++/CLI project? Dealing with WinForms in C++/CLI is really not recommanded...


要将.h文件转换为表单设计器文件,您必须在.vproj文件中进行更改。 br />
示例: - 如果我们有一个Login.h& Login.cpp文件(.cpp文件应该有InitializeComponent()函数定义)并且需要将Login.h文件转换为Login.h [设计](用于编辑Gui)。



在.vproj中搜索Form.h文件条目。

For converting a .h file to a form designer file, you will have to make changes in the .vproj file.
Example: - If we have a Login.h & Login.cpp files (The .cpp file should have InitializeComponent() function definition) and need to convert the Login.h file to Login.h[Design](For editing the Gui).

Search for Form.h file entry in the .vproj.
<File   RelativePath=".\MyProject\GUI\Form.h"    > </File>





将文件类型更改为FileType = 3,并将相应的.resx文件的条目添加到阻止。





Change the file type to "FileType = 3" and also add entry of its corresponding .resx file to the block.

<File
                    RelativePath=".\MyProject\GUI\Form.h"
                    FileType="3"
                    >
                    <File
                        RelativePath=".\MyProject\GUI\Form.resx"
                        SubType="Designer"
                        >
                    </File>
                </File>





保存.vproj中的更改并重新加载项目。这会将simple.h文件转换为设计器文件。





问候

Kedar



Save the changes in .vproj and reload the project. This will convert simple.h file to a designer file.


Regards
Kedar


这是我在* .vcxproj(C ++ / cli)中必须做的事情



< ItemGroup>

< ClInclude Include =Form1.h>

< FileType> CppControl< / FileType> [添加此行]

< / ClInclude>

< / ItemGroup>



< ItemGroup> ;

< EmbeddedResource Include =Form1.resx>

< DependentUpon> Form1.h< / DependentUpon> [添加此行]

< SubType> Designer< / SubType>

< / EmbeddedResource>

< / ItemGroup>



保存并重新启动项目:)
This is what I had to do in the *.vcxproj (C++/cli)

<ItemGroup>
<ClInclude Include="Form1.h">
<FileType>CppControl</FileType> [add this line]
</ClInclude>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.h</DependentUpon> [add this line]
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>

save and restart the project :)


这篇关于如何转换.h文件到win designer ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆