字符串格式代码的放置位置 [英] Where to place String Format code

查看:61
本文介绍了字符串格式代码的放置位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好-

我正在Visual Studio 2017 C#中制作一个小计算器,并试图使显示每3位逗号.我已经花了几个小时阅读Google匹配,包括stackoverflow,而且我已经看到了十几种不同的方法,但是我无法尝试 它们中的任何一个都是因为没有人提及将它们插入应用程序代码的方式和位置.

I am making a little calculator in Visual Studio 2017 C#, and am trying to get the display to have commas every 3 digits. I have been hours reading google hits, including stackoverflow, and I have seen maybe a dozen different ways to do it, but I can't try any of them because nobody mentions how and where they are to be inserted in the app code.

我在所有地方都尝试过,但是对我来说不起作用.

I have tried all over the place and it just doesn't work for me.

我希望得到的是类似于将其放在括号中的第一行中,在私有void button_click(object sender,EventArgs e)下".

What I hoping for is something like "put it in the first line in the bracket, under private void button_click(object sender, EventArgs e)".

非常欢迎使用实际的示例代码.

And an actual piece of example code would be very welcome. 

推荐答案

问候Pratto.

Greetings Pratto.

对此没有简单的答案,因为这取决于其余代码的结构,但总的来说...

There isn't a simple answer to this, because it depends on how the rest of your code is structured, but generally speaking...

您可以将其放置在希望显示发生变化的任何地方.

You put it wherever you are expecting the display to change.

因此,例如,如果您有一个名为button3的按钮,则希望添加一个"3"按钮.单击时,将其放置到显示的末尾,您需要添加一些代码以将"3"添加到并使用称为(可能)button3_Click的方法更新显示. (我说这可能是因为按照惯例这是默认设置,但是您可以更改它.)

So for example, if you have a button called button3 which you expect to add a "3" to the end of the display when it's clicked, you would put some code to add the "3" and update the display in a method called (probably) button3_Click. (I say probably because that's the default by convention, but you can change it).

      private void button3_Click(object sender, EventArgs e)
      {
         // Add the "3" and update the display here.
      }

要创建此方法,必须预订该按钮的click事件.为此,右键单击表单设计器中的按钮,然后选择属性.在属性选项卡上,选择事件窗口(单击小闪电图标),然后双击 列表中的点击事件.

To create this method, you must subscribe to that button's click event. To do that, right-click on the button in the form designer and select properties. On the properties tab select the Events window (click on the little lightning bolt icon), then double-click on the click event in the list.


这篇关于字符串格式代码的放置位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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