简体   繁体   English

如何在C#中向Winforms程序添加功能?

[英]How do I add functionality to a winforms program in C#?

I'm trying to make a winforms version of a program I originally wrote as a console app. 我正在尝试制作最初作为控制台应用程序编写的程序的winforms版本

Here's a picture of my current progress. 这里有一个画面我目前的进展情况。 I've made the text boxes and buttons (with a read-only textbox for output). 我制作了文本框和按钮(带有用于输出的只读文本框)。 I don't know how to actually make the buttons function. 我不知道如何真正使按钮起作用。

I want it to work the same as the console version did (ask for input w/ error messages for anything that isn't an positive integer, and calculate the output), but I've never done winforms before so I'm at a roadblock. 我希望它的工作方式与控制台版本相同(向输入错误消息/输入非正整数的任何错误消息并计算输出),但是我之前从未做过winforms,所以我在路障。

As a beginner to WinForms, you would benefit greatly from reading up on the subject. 作为WinForms的初学者,您可以从阅读该主题中受益匪浅。 For example: 例如:

Just double click the button and it will take you to the code behind page. 只需双击该按钮,它将带您到页面后面的代码。 You can do something as simple as add a textbox (TextBox1) add a button (Button1) 您可以做一些简单的事情,例如添加文本框(TextBox1)和添加按钮(Button1)

Double click button on your winform and it will take you to the click event of the button. 双击Winform上的按钮,它将带您进入按钮的click事件。

In the code behind type this: 在后面的代码中键入以下内容:

TextBox1.Text = "Hello World!";

Now run your app and click the button. 现在运行您的应用程序,然后单击按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM