面向初学者的 C# GUI 编程:从哪里开始?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2016433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# GUI programming for beginners: Where to start?
提问by user63898
I'm a C++/Java developer and have no idea about .Net or GUIs. I need to develop a windows app for 2000/XP/Vista/7.
我是一名 C++/Java 开发人员,对 .Net 或 GUI 一无所知。我需要为 2000/XP/Vista/7 开发一个 Windows 应用程序。
I think I've come to conclusion that C# is the best and the fastest way to go (please correct me if I'm wrong). What do you recommend? Which GUI approach should I learn? (Forms? Any other stuff?)
我想我已经得出结论,C# 是最好和最快的方法(如果我错了,请纠正我)。你有什么建议吗?我应该学习哪种 GUI 方法?(表格?还有其他东西吗?)
Is it the best way to compile in .Net 2.0 mode? It's going to be an application for the public to download.
这是在 .Net 2.0 模式下编译的最佳方式吗?这将是一个供公众下载的应用程序。
采纳答案by Nathan Taylor
In my personal development experience Windows Forms is just about as easy as it gets when it comes to rapidly deploying a GUI application on Windows. WPF is of course another option, but using it would likely require you spend some time familiarizing yourself with XAML. Windows Forms look and feel like a lot of the available GUI options for Java, it's just much better than the majority of them, in my opinion.
根据我的个人开发经验,在 Windows 上快速部署 GUI 应用程序时,Windows 窗体非常简单。WPF 当然是另一种选择,但使用它可能需要您花一些时间熟悉 XAML。Windows 窗体的外观和感觉就像许多可用的 Java 图形用户界面选项,在我看来,它比大多数选项要好得多。
If you want the fastest possible GUI development time in .NET, Windows Forms is it.
如果您想要在 .NET 中实现尽可能快的 GUI 开发时间,Windows 窗体就是它。
回答by Amirshk
C# WinForms will be the fastest in terms of getting a practical GUI working rapidly. Though if you think on making a complex GUI, with animations, 3D etc, WPF would be better.
C# WinForms 将是让实用 GUI 快速运行的最快方法。虽然如果你想制作一个复杂的 GUI,带有动画、3D 等,WPF 会更好。
You can use CodePlexto find some good working projects to learn from in terms of best practice, both for WinForms and WPF.
您可以使用CodePlex找到一些很好的工作项目,以学习 WinForms 和 WPF 的最佳实践。
You can also look herefor some good books on both WPF and WinForms.
您还可以在此处查看有关 WPF 和 WinForms 的一些好书。
回答by Adam Crossland
You could use Windows Forms or Windows Presentation Foundation to develop your GUI; although, Windows Forms might feel more familiar to you. If you search on Google for Windows Forms tutorial, you will get many options for getting started.
您可以使用 Windows Forms 或 Windows Presentation Foundation 来开发您的 GUI;不过,您可能会觉得 Windows 窗体更熟悉。如果您在 Google 上搜索Windows 窗体教程,您将获得许多入门选项。
If you need to use .NET 2.0, you will be limited to Win Forms. WPF requires .NET 3.5.
如果您需要使用 .NET 2.0,您将仅限于使用 Win Forms。WPF 需要 .NET 3.5。
I would suggest downloading Microsoft's free Visual Studio Express Editionto use for developemnt. it includes an excellent drag-and-drop GUI design tool.
我建议下载 Microsoft 的免费Visual Studio Express Edition以用于开发。它包括一个出色的拖放式 GUI 设计工具。
回答by stiank81
For desktop applications there are basically two options; WinFormsand Windows Presentation Foundation(WPF).
对于桌面应用程序,基本上有两种选择;WinForms和Windows Presentation Foundation(WPF)。
WinForms is more traditionally built and hence easier to learn. WinForms might therefore be a simpler start, but if you plan on actually using your gained knowledge in GUI development for .NET I'd say you're better of diving into WPF from the start. It's a much richer framework, and where Microsoft is putting their effort for desktop applications. It is also similar to Silverlight, meaning you can easily get into Silverlight too when you know WPF.
WinForms 是更传统的构建方式,因此更容易学习。因此,WinForms 可能是一个更简单的开始,但如果您打算实际使用您在 .NET 的 GUI 开发中获得的知识,我会说您最好从一开始就深入研究 WPF。这是一个更丰富的框架,微软正在为桌面应用程序付出努力。它也类似于 Silverlight,这意味着当您了解 WPF 时,您也可以轻松地进入 Silverlight。
- This other questiongives some useful resources when getting started with WPF.
- Also check out this tutorial at MSDN.
- WpfTutorialobviously has a few nice hints for you too!
- 另一个问题在开始使用 WPF 时提供了一些有用的资源。
- 还可以在 MSDN 上查看本教程。
- WpfTutorial显然也为您提供了一些不错的提示!
Good luck!
祝你好运!
回答by Duncan Bayne
I think I've come to conclusion that C# is the best and the fastest way to go (please correct me if I'm wrong). What do you recommend?
我想我已经得出结论,C# 是最好和最快的方法(如果我错了,请纠正我)。你有什么建议吗?
Personally, I would stick with Java. We (meaning OffByZero, the company I co-founded) have released an encrypted text editor called OBZVault, which is written in Java.
就个人而言,我会坚持使用 Java。我们(指的是OffByZero,我共同创立的公司)发布了一个名为OBZVault的加密文本编辑器,它是用 Java 编写的。
We originally wrote it in Linux, and then ported to Mac OS X and Windows. We found that the Windows port provided a perfectly acceptable look & feel - almost (but not exactly) like a native Windows app.
我们最初是用 Linux 编写的,然后移植到 Mac OS X 和 Windows。我们发现 Windows 端口提供了完全可以接受的外观和感觉 - 几乎(但不完全)像本机 Windows 应用程序。
We used InnoSetupto build a native Windows installer, and found that quite good as well.
我们使用InnoSetup构建了一个本地 Windows 安装程序,并且发现它也非常好。
Bottom line: unless you want to learn a new language & platform, or you have a specific need for functionality provided by a different platform like .NET, stick with Java for your Windows development too. You'll need to learn a Java GUI framework, but then you'd have to learn WPF or WinForms if you switched to .NET anyway.
底线:除非您想学习一种新的语言和平台,或者您对 .NET 等不同平台提供的功能有特定需求,否则也请坚持使用 Java 进行 Windows 开发。您需要学习 Java GUI 框架,但如果您切换到 .NET,则必须学习 WPF 或 WinForms。
It may be faster for an experienced .NET developerto build a Windows app in WinForms or WPF, but if you're already well versed in Java I say stick with the tools (language, libraries, IDE) that you know.
对于有经验的 .NET 开发人员来说,在 WinForms 或 WPF 中构建 Windows 应用程序可能会更快,但如果您已经精通 Java,我会说坚持使用您知道的工具(语言、库、IDE)。
回答by SwDevMan81
I would recommend learning Winforms first, then move the WPF. Winforms is easier to learn and get something working quickly. The future however is WPF, so I wouldnt leave that in the dark. I posted some good books and links for GUI development work.
我建议先学习 Winforms,然后移动 WPF。Winforms 更容易学习并且可以快速运行。然而,未来是 WPF,所以我不会把它留在黑暗中。我发布了一些关于 GUI 开发工作的好书和链接。
Books
图书
- Design of Everyday ThingsA really good book about design of interfaces. It's not software specific but a must read for GUI designers.
- Coding Horror. He recommends a lot of development books on his book list, but these ones are specifically interface-related:
- Design of Everyday Things一本关于界面设计的好书。它不是特定于软件的,而是 GUI 设计人员的必读之物。
- 编码恐怖。他在他的书单上推荐了很多开发书籍,但这些都是专门与接口相关的:
Don't Make Me Think
About Face 3.0
The Inmates Are Running the Asylum
GUI Bloopers
不要让我考虑
Face 3.0
囚犯正在运行庇护
GUI Bloopers
Web Links
网页链接
- Are Confirmation Dialogs Harmful?A blog entry by Guido van Rossum (creator of Python)
- GUI ArticlesA few articles about GUIs by Joel Spolsky (joelonsoftware.com)
- Interfaced Systems InternationalHas a lot of resources, especially on their UI Referencespage
- User Experience Guidelines for Windows Vista
- 确认对话框有害吗?Guido van Rossum(Python 的创建者)的博客条目
- GUI 文章Joel Spolsky (joelonsoftware.com) 的一些关于 GUI 的文章
- Interfaced Systems International有很多资源,尤其是在他们的UI References页面上
- Windows Vista 用户体验指南
回答by codekaizen
I disagree with all the WinForms advocates. It's not easier. It may be easier for someone who has traditional experience with GUI programming, but this poster doesn't have that.
我不同意所有 WinForms 的拥护者。这并不容易。对于具有 GUI 编程传统经验的人来说,这可能更容易,但这张海报没有。
WPF has a better design story and the databinding is much, much better than WinForms. You can get up and running on WPF at least as fast as WinForms, and then go much further without running into the limitations that WinForms has. Couple this with the design-time databinding in VS 2010, and I'd say that anyone starting out on GUI development should completely bypass Winforms.
WPF 有更好的设计故事,数据绑定比 WinForms 好得多。您至少可以像 WinForms 一样快地启动和运行 WPF,然后再进一步,而不会遇到 WinForms 的限制。将此与 VS 2010 中的设计时数据绑定相结合,我想说任何开始 GUI 开发的人都应该完全绕过 Winforms。
回答by pm100
C# for sure. Use Winforms for line of business app / classic GUI.
C# 是肯定的。将 Winforms 用于业务线应用程序/经典 GUI。
read petzold 'programming windows with c#'
阅读 petzold '用 c# 编程窗口'
Or just dive in with visual studio. Creating GUI with VS is really easy - you will like it
或者只是潜入视觉工作室。用 VS 创建 GUI 真的很简单——你会喜欢的
You will find the langauge transition from java to c# pretty simple (not the gui bit tho)
你会发现从 Java 到 C# 的语言转换非常简单(不是 gui 位)
回答by no.human.being
Yes. C# is the language of choice when it comes to .NET development. Since you've programmed in Java, you'll find that the language looks very familiar (it looks a bit cleaner though and has some very nice features like delegates and you can even use pointers if you really want to, although you won't need to in most circumstances).
是的。C# 是 .NET 开发的首选语言。由于您已经用 Java 编程,您会发现该语言看起来非常熟悉(尽管它看起来更简洁,并且具有一些非常好的特性,例如委托,如果您真的想要,您甚至可以使用指针,尽管您不会大多数情况下需要)。
It's SWF (System Windows Forms) or MWF (Managed Windows Forms - a lightweight version of SWF written in managed Code using System.Drawing - it frees you from the WinAPI that's underlying classical SWF) all the way.
它是 SWF(系统 Windows 窗体)或 MWF(托管 Windows 窗体 - 使用 System.Drawing 以托管代码编写的 SWF 的轻量级版本 - 它使您完全摆脱了作为基础经典 SWF 的 WinAPI)。
There's also GTK-Sharp, a GTK+ binding for C-Sharp, but since you're developing for Windows, users will find it strange to install a third-party GUI framework for your application.
还有 GTK-Sharp,它是 C-Sharp 的 GTK+ 绑定,但是由于您是为 Windows 开发的,用户会发现为您的应用程序安装第三方 GUI 框架很奇怪。
I wouldn't recommend using WPF though. It makes direct calls to the underlying graphics hardware, which means it's quite fast, but not portable at all. It will only run on x86 systems (not SPARC, etc.) with DirectX compliant hardware rendering units (graphics cards) and it will not run on a system with strong hardware abstraction (like most Unices like BSD or Linux or Solaris).
不过我不建议使用 WPF。它直接调用底层图形硬件,这意味着它非常快,但根本不便携。它只能在具有 DirectX 兼容硬件渲染单元(图形卡)的 x86 系统(不是 SPARC 等)上运行,并且不会在具有强大硬件抽象的系统上运行(如大多数 Unices,如 BSD 或 Linux 或 Solaris)。
Novell also stated that they will never implement WPF in the near future due to it's strong hardware dependencies (Novell wants Mono to be portable across many processor platforms). Don't use WPF. Software is no longer just a throw-away-product and when it comes to operating systems we're in the age of spin. The platform you're running today isn't necessarily the platform you're gonna run tomorrow. WPF is a proprietary and patent-encumbered technology developed by Microsoft and Intel. If you use it, you'll find yourself in a very nice Win32-on-x86 vendor lock in. And this means that you'll most definitely find yourself completely re-writing your application sooner or later. Just write portable software from the beginning, even if you don't need that portability today. I'm telling you from experience, you will need portability tomorrow. Definitely!
Novell 还表示,由于 WPF 具有很强的硬件依赖性(Novell 希望 Mono 在许多处理器平台上可移植),他们在不久的将来永远不会实现 WPF。不要使用 WPF。软件不再只是一次性产品,而当涉及到操作系统时,我们正处于旋转时代。你今天运行的平台不一定是你明天要运行的平台。WPF 是由 Microsoft 和 Intel 开发的专有和受专利保护的技术。如果您使用它,您会发现自己处于一个非常好的 Win32-on-x86 供应商锁定中。这意味着您迟早会发现自己完全重新编写您的应用程序。只需从一开始就编写可移植软件,即使您今天不需要那种可移植性。我用经验告诉你,明天你将需要便携性。确实!