首页 > 解决方案 > 在 C# Windows 窗体中单击时如何停止文本在按钮中移动?

问题描述

所以我正在以 Windows 形式制作一个基本的计算器,并且对 C# 很陌生。我有 +、-、/ 和 * 的按钮,由于某种原因,当我运行程序时,如果单击“-”按钮,“-”符号会移动到按钮的底部。每次我运行程序并尝试将边距和填充设置为 0 并锚定但无法解决它时,都会发生这种情况。其他 3 个按钮不会发生这种情况,除了符号和按钮编号外,它们的代码都相同。我从工具箱中拖出控件,所以没有编写任何代码,这就是我如此困惑的原因。

按钮的代码如下:

        this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F);
        this.button2.Location = new System.Drawing.Point(209, 174);
        this.button2.Margin = new System.Windows.Forms.Padding(0);
        this.button2.Name = "button2";
        this.button2.Size = new System.Drawing.Size(50, 50);
        this.button2.TabIndex = 4;
        this.button2.Text = "−";
        this.button2.UseVisualStyleBackColor = true;
        this.button2.Click += new System.EventHandler(this.button2_Click);

代码的边缘行是与其他 3 个按钮唯一不同的行,但无论有没有该行,问题仍然存在。任何帮助将非常感激!

标签: c#

解决方案


推荐阅读