syncfusion-winforms-calculator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Implementing Syncfusion Windows Forms Calculator

实现Syncfusion Windows Forms计算器

The Syncfusion Calculator control is a fully-featured calculator for Windows Forms applications. It supports both standard and financial layouts, keyboard operations, memory functions, and can be embedded as a popup control.
Syncfusion计算器控件是适用于Windows Forms应用的全功能计算器组件,支持标准和财务两种布局、键盘操作、内存功能,还可以作为弹出控件嵌入使用。

When to Use This Skill

何时使用本技能

Use the Calculator control when your application needs:
  • Standard or scientific calculator functionality
  • Keyboard and mouse input support
  • Memory operations (MS, MR, M+, MC)
  • Popup calculator attached to input fields
  • Display of calculation results and intermediate values
  • Support for both C# and VB.NET
当你的应用需要以下能力时,可以使用该计算器控件:
  • 标准或科学计算器功能
  • 键盘和鼠标输入支持
  • 内存操作(MS、MR、M+、MC)
  • 依附于输入框的弹出式计算器
  • 计算结果和中间值展示
  • 同时支持C#和VB.NET

Component Overview

组件概览

CalculatorControl — The main calculator component with layout modes, keyboard support, and value calculation events
PopupCalculator — A wrapper class to display CalculatorControl as a popup attached to buttons or other controls
CalculatorControl — 核心计算器组件,支持布局模式切换、键盘输入、数值计算事件
PopupCalculator — 封装类,可将CalculatorControl作为弹出控件展示,依附于按钮或其他控件

Key Characteristics

核心特性

  • Two layout modes: Standard (default) and Financial
  • Full keyboard support with standard calculator shortcuts
  • Memory management (MS, MR, M+, MC operations)
  • Display TextBox with customizable alignment and font
  • Event-driven architecture (ValueCalculated, Closing events)
  • Culture-aware value formatting
  • Lightweight, embeddable component
  • 两种布局模式:标准(默认)和财务
  • 完整的键盘支持,兼容标准计算器快捷键
  • 内存管理(MS、MR、M+、MC操作)
  • 展示用TextBox,支持自定义对齐方式和字体
  • 事件驱动架构(ValueCalculated、Closing事件)
  • 适配不同文化的数值格式化
  • 轻量可嵌入的组件

Documentation and Navigation Guide

文档与导航指南

Getting Started

入门指南

📄 Read: references/getting-started.md
  • Assembly dependencies and NuGet installation
  • Create Windows Forms project with Calculator
  • Add control via Designer or manual code
  • Required namespaces and basic instantiation
📄 阅读: references/getting-started.md
  • 程序集依赖和NuGet安装
  • 创建带有计算器的Windows Forms项目
  • 通过设计器或手动代码添加控件
  • 所需命名空间和基础实例化方法

Layout and Appearance

布局与外观

📄 Read: references/layout-and-appearance.md
  • Standard vs Financial layout modes
  • Background color and images
  • Border styles
  • Button spacing and styling
  • Display text alignment
📄 阅读: references/layout-and-appearance.md
  • 标准与财务布局模式对比
  • 背景色和背景图片设置
  • 边框样式
  • 按钮间距和样式
  • 展示文本对齐方式

Display and Value Handling

展示与数值处理

📄 Read: references/display-and-value-handling.md
  • Display TextBox properties and visibility
  • Managing numeric values (String vs Double)
  • Culture-specific formatting
  • Font customization
📄 阅读: references/display-and-value-handling.md
  • 展示TextBox的属性和可见性设置
  • 数值管理(字符串与双精度浮点数)
  • 特定文化的格式化
  • 字体自定义

Keyboard and Runtime Features

键盘与运行时特性

📄 Read: references/keyboard-and-runtime-features.md
  • Complete keyboard shortcut reference
  • Memory operations (MS, MR, M+, MC)
  • Numeric operations and calculations
  • Special functions (sqrt, reciprocal, percentage)
📄 阅读: references/keyboard-and-runtime-features.md
  • 完整的键盘快捷键参考
  • 内存操作(MS、MR、M+、MC)
  • 数值运算与计算
  • 特殊功能(平方根、倒数、百分比)

Events and Interaction

事件与交互

📄 Read: references/events-and-interaction.md
  • ValueCalculated event handling
  • Closing event for PopupCalculator
  • LastAction property for determining completed operations
  • Error condition handling
📄 阅读: references/events-and-interaction.md
  • ValueCalculated事件处理
  • PopupCalculator的Closing事件
  • 用于判断已完成操作的LastAction属性
  • 错误状态处理

Popup Calculator

弹出式计算器

📄 Read: references/popup-calculator.md
  • Creating PopupCalculator instances
  • ParentControl association
  • Popup alignment options
  • Displaying and using popup calculator
📄 阅读: references/popup-calculator.md
  • 创建PopupCalculator实例
  • 父控件关联
  • 弹出对齐选项
  • 弹出计算器的展示与使用

Quick Start Example

快速入门示例

csharp
using Syncfusion.Windows.Forms.Tools;
using System.Windows.Forms;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        
        // Create Calculator control
        CalculatorControl calculatorControl = new CalculatorControl();
        calculatorControl.Size = new System.Drawing.Size(300, 250);
        calculatorControl.LayoutType = CalculatorLayoutTypes.WindowsStandard;
        
        // Add to form
        this.Controls.Add(calculatorControl);
        
        // Handle value changes
        calculatorControl.ValueCalculated += (sender, args) =>
        {
            if (!args.ErrorCondition && args.LastAction == CalcActions.CalcOperatorEquals)
            {
                MessageBox.Show($"Result: {calculatorControl.Value}");
            }
        };
    }
}
csharp
using Syncfusion.Windows.Forms.Tools;
using System.Windows.Forms;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        
        // Create Calculator control
        CalculatorControl calculatorControl = new CalculatorControl();
        calculatorControl.Size = new System.Drawing.Size(300, 250);
        calculatorControl.LayoutType = CalculatorLayoutTypes.WindowsStandard;
        
        // Add to form
        this.Controls.Add(calculatorControl);
        
        // Handle value changes
        calculatorControl.ValueCalculated += (sender, args) =>
        {
            if (!args.ErrorCondition && args.LastAction == CalcActions.CalcOperatorEquals)
            {
                MessageBox.Show($"Result: {calculatorControl.Value}");
            }
        };
    }
}

Common Patterns

常用模式

Pattern 1: Standard Calculator with Event Handling

模式1:带事件处理的标准计算器

Create a calculator that logs all operations and displays final results when "=" is pressed.
csharp
CalculatorControl calc = new CalculatorControl();
calc.ValueCalculated += (sender, args) =>
{
    if (!args.ErrorCondition && args.LastAction == CalcActions.CalcOperatorEquals)
    {
        // Process final value
        double result = calc.DoubleValue;
    }
};
创建一个可记录所有操作,按下「=」时展示最终结果的计算器。
csharp
CalculatorControl calc = new CalculatorControl();
calc.ValueCalculated += (sender, args) =>
{
    if (!args.ErrorCondition && args.LastAction == CalcActions.CalcOperatorEquals)
    {
        // Process final value
        double result = calc.DoubleValue;
    }
};

Pattern 2: Popup Calculator on Button Click

模式2:点击按钮弹出的计算器

Embed calculator as a popup that displays when button is clicked.
csharp
PopupCalculator popupCalc = new PopupCalculator();
popupCalc.ParentControl = myButton;
popupCalc.PopupCalculatorAlignment = CalculatorPopupAlignment.Right;
popupCalc.Closing += (sender, args) => 
{
    decimal finalValue = args.FinalValue;
};
将计算器作为弹出组件嵌入,点击按钮时展示。
csharp
PopupCalculator popupCalc = new PopupCalculator();
popupCalc.ParentControl = myButton;
popupCalc.PopupCalculatorAlignment = CalculatorPopupAlignment.Right;
popupCalc.Closing += (sender, args) => 
{
    decimal finalValue = args.FinalValue;
};

Pattern 3: Financial Layout with Custom Styling

模式3:带自定义样式的财务布局计算器

Display a financial calculator with custom appearance.
csharp
CalculatorControl calc = new CalculatorControl();
calc.LayoutType = CalculatorLayoutTypes.Financial;
calc.DisplayTextAlign = System.Windows.Forms.HorizontalAlignment.Right;
calc.UseVerticalAndHorizontalSpacing = true;
calc.HorizontalSpacing = 5;
calc.VerticalSpacing = 5;
展示自定义外观的财务计算器。
csharp
CalculatorControl calc = new CalculatorControl();
calc.LayoutType = CalculatorLayoutTypes.Financial;
calc.DisplayTextAlign = System.Windows.Forms.HorizontalAlignment.Right;
calc.UseVerticalAndHorizontalSpacing = true;
calc.HorizontalSpacing = 5;
calc.VerticalSpacing = 5;

Key Properties

核心属性

PropertyPurposeNotes
LayoutType
Switch between Standard and Financial layoutsDefault is WindowsStandard
ShowDisplayArea
Show/hide the display TextBoxTrue by default
DoubleValue
Get/set numeric value as doubleUse for calculations
Value
Get current valueReturns CalculatorValue object
Culture
Set culture for number formattingAffects decimal separator
DisplayTextAlign
Align display text (Left/Center/Right)Default is Right
FlatStyle
Button appearance (Flat/Popup/Standard)Changes button rendering
属性用途说明
LayoutType
在标准和财务布局之间切换默认是WindowsStandard
ShowDisplayArea
展示/隐藏展示用TextBox默认值为True
DoubleValue
以双精度浮点数格式获取/设置数值用于计算场景
Value
获取当前值返回CalculatorValue对象
Culture
设置数值格式化的文化规则影响小数分隔符展示
DisplayTextAlign
对齐展示文本(左/中/右)默认是右对齐
FlatStyle
按钮外观(扁平/弹出/标准)改变按钮渲染效果

Common Use Cases

常见使用场景

  1. Financial Calculator — Use Financial layout mode with memory operations for accounting applications
  2. Quick Calculation Popup — Attach PopupCalculator to TextBox for quick value entry
  3. Multi-Input Form — Place calculator on form for users to compute values before entering
  4. Keyboard-Only Input — Calculator accessible via keyboard shortcuts in keyboard-driven apps
  5. Value Validation — Display calculator result in TextBox after "=" pressed

  1. 财务计算器 — 在会计类应用中使用财务布局模式搭配内存操作
  2. 快速计算弹出框 — 将PopupCalculator依附在TextBox上,方便快速输入数值
  3. 多输入表单 — 在表单上放置计算器,方便用户计算后录入数值
  4. 纯键盘输入 — 在键盘驱动的应用中,用户可通过快捷键操作计算器
  5. 数值校验 — 按下「=」后将计算器结果展示在TextBox中

Next Steps

后续步骤

  • Start with Getting Started to add the control to your project
  • Explore Layout and Appearance to customize the UI
  • Review Events and Interaction to handle user operations
  • 先阅读入门指南将控件添加到你的项目中
  • 探索布局与外观文档自定义UI
  • 查看事件与交互文档学习如何处理用户操作