编辑
2025-10-05
C#
00

OxyPlot是一个功能强大的跨平台绘图库,可以在WinForms应用程序中创建各种类型的图表,包括饼状图。本指南将介绍如何在WinForms应用程序中使用OxyPlot创建和自定义饼状图。

环境设置

首先,确保您的WinForms项目中已安装OxyPlot库。您可以通过NuGet包管理器安装:

C#
Install-Package OxyPlot.WindowsForms

基本饼状图

让我们从一个简单的饼状图开始:

C#
using OxyPlot; using OxyPlot.Series; using OxyPlot.WindowsForms; private void CreateBasicPieChart() { var model = new PlotModel { Title = "基本饼状图" }; var series = new PieSeries { StrokeThickness = 2.0, InsideLabelPosition = 0.8, AngleSpan = 360, StartAngle = 0 }; series.Slices.Add(new PieSlice("苹果", 3) { IsExploded = true }); series.Slices.Add(new PieSlice("香蕉", 4)); series.Slices.Add(new PieSlice("橙子", 2)); model.Series.Add(series); var plotView = new PlotView { Model = model, Dock = DockStyle.Fill }; this.Controls.Add(plotView); }

image.png

编辑
2025-10-05
C#
00

OxyPlot是一个强大的跨平台绘图库,可以在WinForms应用程序中创建高质量的图表。本指南将重点介绍如何使用OxyPlot在WinForms中创建各种类型的柱状图。

环境设置

首先,您需要在您的WinForms项目中安装OxyPlot。您可以通过NuGet包管理器安装以下包:

  • OxyPlot.Core
  • OxyPlot.WindowsForms

image.png

在Visual Studio中,右键点击您的项目,选择"管理NuGet包",然后搜索并安装这两个包。

安装完成后,在您的代码中添加以下using语句:

C#
using OxyPlot; using OxyPlot.Series; using OxyPlot.WindowsForms;
编辑
2025-10-05
C#
00

在Windows Forms应用程序中,ListView是一个非常实用的控件,用于显示数据列表。但默认情况下,ListView并不支持点击列头进行排序。本文将介绍如何开发一个可点击列头排序的ListView控件。

创建自定义比较器

ListViewItemSorter 类是一个用于排序 ListView 控件中项目的自定义比较器。它实现了 IComparer<ListViewItem> 接口,可以按照指定的列、排序顺序和数据类型对 ListViewItem 进行排序。

C#
public class ListViewItemSorter : IComparer<ListViewItem> { private int _columnIndex; private SortOrder _sortOrder; private ColumnDataType _dataType; public ListViewItemSorter(int columnIndex, SortOrder sortOrder, ColumnDataType dataType) { _columnIndex = columnIndex; _sortOrder = sortOrder; _dataType = dataType; } public int Compare(ListViewItem x, ListViewItem y) { string textX = x.SubItems[_columnIndex].Text; string textY = y.SubItems[_columnIndex].Text; int result; switch (_dataType) { case ColumnDataType.Number: if (double.TryParse(textX, out double numX) && double.TryParse(textY, out double numY)) { result = numX.CompareTo(numY); } else { result = string.Compare(textX, textY, StringComparison.OrdinalIgnoreCase); } break; case ColumnDataType.Date: if (DateTime.TryParse(textX, out DateTime dateX) && DateTime.TryParse(textY, out DateTime dateY)) { result = dateX.CompareTo(dateY); } else { result = string.Compare(textX, textY, StringComparison.OrdinalIgnoreCase); } break; case ColumnDataType.Text: default: result = string.Compare(textX, textY, StringComparison.OrdinalIgnoreCase); break; } return _sortOrder == SortOrder.Ascending ? result : -result; } }
  1. 构造函数接受三个参数:
    • columnIndex:要排序的列的索引
    • sortOrder:排序顺序(升序或降序)
    • dataType:列数据的类型(数字、日期或文本)
  2. Compare 方法实现了实际的比较逻辑:
    • 根据指定的列索引获取要比较的文本
    • 根据数据类型进行相应的比较:
      • 对于数字类型,尝试将文本转换为 double 进行比较
      • 对于日期类型,尝试将文本转换为 DateTime 进行比较
      • 对于文本类型或无法转换的情况,使用字符串比较
  3. 比较结果会根据指定的排序顺序进行调整(升序或降序)
编辑
2025-10-05
C#
00

OxyPlot是一个强大的跨平台绘图库,非常适合在WinForms应用程序中创建各种类型的图表。本指南将重点介绍如何使用OxyPlot创建各种线图,并提供多个完整的示例。

环境设置

首先,确保您已经安装了OxyPlot。在Visual Studio中,通过NuGet包管理器安装以下包:

  • OxyPlot.Core
  • OxyPlot.WindowsForms

或者在包管理器控制台中运行:

C#
Install-Package OxyPlot.Core Install-Package OxyPlot.WindowsForms

image.png 在您的Form类中,添加以下using语句:

C#
using OxyPlot; using OxyPlot.Series; using OxyPlot.WindowsForms;

基本线图

让我们从一个基本的线图开始。这个例子展示了如何创建一个简单的正弦波线图。

C#
public partial class Form1 : Form { public Form1() { InitializeComponent(); CreateBasicLineChart(); } private void CreateBasicLineChart() { var plotView = new PlotView(); plotView.Dock = DockStyle.Fill; this.Controls.Add(plotView); var plotModel = new PlotModel { Title = "Basic Line Chart" }; var series = new LineSeries { Title = "sin(x)" }; for (double x = 0; x < 10; x += 0.1) { series.Points.Add(new DataPoint(x, Math.Sin(x))); } plotModel.Series.Add(series); plotView.Model = plotModel; } }

image.png

编辑
2025-10-05
C#
00

AntdUI是一个基于Ant Design设计体系的.NET UI组件库,为WinForms和WPF应用程序提供了丰富的现代化UI控件。它允许开发者快速构建美观、响应式的桌面应用程序界面,同时保持了.NET平台的强大功能和灵活性。

主要特性

  1. 丰富的组件:提供了大量常用的UI组件,如按钮、输入框、表格、菜单等。
  2. 现代设计:遵循Ant Design的设计规范,确保美观和一致性。
  3. 易于使用:API设计直观,易于集成到现有项目中。
  4. 高度可定制:支持主题定制,可以根据需求调整样式。
  5. 性能优化:针对.NET平台优化,确保流畅的用户体验。

官网

Markdown
https://gitee.com/antdui/AntdUI

安装

要在您的项目中使用AntdUI,您可以通过NuGet包管理器安装:

Markdown
Install-Package AntdUI

或者使用.NET CLI:

Markdown
dotnet add package AntdUI

image.png

image.png