Visual C++ 2008 Express,将离散的 GUI 元素封装到单独的文件中

发布于 2024-11-26 19:41:46 字数 1028 浏览 1 评论 0 原文

我想使用 VC9 和 VC9 制作自己的组件。 Visual Studio 2008 Express。目前,我的顶级 Form 类包含太多我不喜欢的代码,我想扩展它们。

我可以安全地到达 Project->Add...->Component_Class。

接下来,我使用文本框、提交按钮和面板来命名并填充组件,以代表可以将评论提交到的不同渠道(所有、团队、对手)的选项卡,并在下面使用富文本框进行更新取决于所选的选项卡。

我打破了规则

#pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>

唯一的问题是,当我为子组件设置位置时,

。那我就无法将这个新组件放入我的工具箱中。

VC++2008 Express 可以吗?

_编辑_

所以我遵循了这个,http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=151764&SiteID=1 建议并在我的工具箱。

现在的问题是它只是“不可视”,因为图像列表位于表单设计区域之外的自己的栏中:(

将尝试扩展比

系统::组件模型::组件

_编辑_

我自己回答了这个问题,并整理了标题和标签以供将来参考。

I would like to make my own compenents using, and for, VC9 & Visual Studio 2008 Express. Currently my top level Form classes contain too much code for my liking, and I want to grow them.

I can safely get as far as Project->Add...->Component_Class.

Next I name and populate the component with, say, a text box, submit button, and panel to represent tabs for the different channels the comment can be submitted to (all, team, opponent) with a rich text box below which I will update depending on the tab selected.

Only trouble is I am breaking the

#pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>

When I come to setting positions for my sub-components.

That and I can't get this new component into my toolbox.

Is it possible with VC++2008 Express?

_EDIT_

So I followed this, http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=151764&SiteID=1 advice and got the component in my toolbox.

Problem now is it is just 'unvisual' as the image lists sitting in their own bar off of the Form design area :(

Will try to extend a more substantial class than

System::ComponentModel::Component

_EDIT_

I've since answered this myself and tidied up the title and tags for future reference.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别靠近我心 2024-12-03 19:41:46

下面的文章是关于在Visual Studio和C#中创建自定义控件的,希望对您有用。看起来它可能是在旧版本的 VS/C# 中,但 Windows 窗体内容无论如何都相当旧

http://www.akadia.com/services/dotnet_user_controls.html

您可能需要考虑编写 WPF 应用程序作为 Windows 窗体的替代方案 - 这是一种用于构建 Windows 桌面应用程序的更新技术,并且部分技术与 Silverlight 等其他 Microsoft 工具共享。

如果您有兴趣,这里有一个关于如何在 WPF 中构建自定义控件的教程:

http://www.abhisheksur.com/2011/07/writing-reusable-custom-control-in-wpf.html

更新:看看 VS2008Express 的功能 - 您无法制作 WPF 自定义控件,因此很明显,如果您仅限于该环境,那么您将不得不使用 Windows 窗体。教程在上面。

The following article is about creating custom controls in Visual Studio and C#, I hope it is useful to you. It looks like it might be in an older version of VS/C#, but the Windows Forms stuff is quite old anyway

http://www.akadia.com/services/dotnet_user_controls.html

You might want to consider writing WPF applications as an alternative to Windows Forms - this is a more up to date technology for building desktop applications for Windows, and some of the technology is shared with other Microsoft tools such as Silverlight.

And here is a tutorial for how to build custom controls in WPF if you're interested:

http://www.abhisheksur.com/2011/07/writing-reusable-custom-control-in-wpf.html

Update: So looking at the capabilities of VS2008Express - you can't make WPF custom controls, so clearly if you're limited to that environment then you're going to have to go with Windows Forms. The tutorial is above.

安静被遗忘 2024-12-03 19:41:46

如果有人感兴趣,我发现了如何在 VC++ 2008 中创建自定义组件。

您不使用表单设计器,但必须以编程方式完成。好吧,我作弊并从我首先使用表单设计器创建的原型模型中获取了大部分代码。

此信息的来源是 UserControl 类的 SDK 文档,

http://msdn.microsoft.com/en-us/library/system.windows.forms.usercontrol%28v=VS.90%29.aspx

通过将上面链接中的示例代码添加到我的项目中,我可以通过选择使用表单设计器将其添加为可视组件

“工具 > 选项 > Windows 窗体设计器 > 常规:
自动工具箱填充”

我现在已经将所有 GUI 代码卸载到它们自己的类中,通常我

#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System::ComponentModel;

namespace myProjNS { 之前添加以下内容,并继续声明一个扩展其他一些 Forms 组件的类。

我现在很欣赏它的优点上述答案,但它们都需要 C#,而在我提出问题时,我的有限系统上不支持 C#。

If anyone is interested, I found how to create custom components in VC++ 2008.

You don't use the Forms designer but must do it programmatically. Well, I cheated and got most of the code from a proto-mock-up which I first created with the Form Designer.

The source of this info was the SDK documentation for the UserControl class,

http://msdn.microsoft.com/en-us/library/system.windows.forms.usercontrol%28v=VS.90%29.aspx

By adding the sample code in the above linke to my project I was able to add it as visual component using the Forms Designer by selecting

"Tools > Options > Windows Forms Designer > General :
AutoToolboxPopulate"

I've now offloaded all my GUI code to their own classes and generally I add the following

#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System::ComponentModel;

before namespace myProjNS { and proceeding to declare a class which extends some other Forms component.

I now appreciate the merits of the above answers, but they all require C# which was not available on my limited system at the time I asked the question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文