Click here to Skip to main content
15,867,686 members
Articles / Database Development / Data Visualization

Winforms-datavisualization .NET 5

Rate me:
Please Sign up or sign in to vote.
5.00/5 (9 votes)
22 Apr 2021MIT2 min read 23.2K   1K   9   17
.NET 5 version of dotnet/winforms-datavisualization

Rought porting to .NET5 of dotnet/winforms-datavisualization project and the sample solution as well.

Data Visualization

This repository contains partial source code of the System.Windows.Forms.DataVisualization namespace that provides charting for WinForms. Microsoft ported and open sourced those components to enable charting features for WinForms applications that are developed on .NET Core 3.

I've made the porting to .NET 5:

  • Updating references
  • Updating project files
  • Moving deprecated controls like ContextMenu, MenuItems to new ones (ContextMenuStrip, ToolStripMenuItems) and relative methods
  • ...

Application Running .NET 5:

ApplicationRunning

Points of Interest

Removed Controls starting With .NET Core 3.1

Starting with .NET Core 3.1, various Windows Forms controls are no longer available. Replacement controls that have better design and support were introduced in .NET Framework 2.0. The deprecated controls were previously removed from designer toolboxes but were still available to be used (source).

The following types are no longer available:

  • ContextMenu
  • DataGrid
  • DataGrid.HitTestType
  • DataGridBoolColumn
  • DataGridCell
  • DataGridColumnStyle
  • DataGridLineStyle
  • DataGridParentRowsLabelStyle
  • DataGridPreferredColumnWidthTypeConverter
  • DataGridTableStyle
  • DataGridTextBox
  • DataGridTextBoxColumn
  • GridColumnStylesCollection
  • GridTablesFactory
  • GridTableStylesCollection
  • IDataGridEditingService
  • IMenuEditorService
  • MainMenu
  • Menu
  • Menu.MenuItemCollection
  • MenuItem
  • ToolBar
  • ToolBarAppearance
  • ToolBarButton
  • ToolBar.ToolBarButtonCollection
  • ToolBarButtonClickEventArgs
  • ToolBarButtonStyle
  • ToolBarTextAlign

RECOMMENDED ACTION

Removed control (API) Recommended replacement
ContextMenu ContextMenuStrip
MenuItem ToolStripMenuItem

That's what has been performed on the project.

References

The original port to .NET Core 3.0 used very old and still in Beta/Preview references:

RefPackages

and moving away from them was a bit tricky, now they're all actualized:

RefPack2

In a future release, maybe the use of System.Data.SqlClient should be avoided ...

CSProj

The CSProj files were also modified according to the new target / Platform (Windows):

Original (Relavant Portion):

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <AssemblyName>System.Windows.Forms.DataVisualization</AssemblyName>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <CLSCompliant>false</CLSCompliant>
    <NoWarn>$(NoWarn);618</NoWarn>
    <DefineConstants>$(DefineConstants);WINFORMS_CONTROL</DefineConstants>
    <!-- <Win32Manifest>Resources\System\Windows\Forms\XPThemes.manifest</Win32Manifest> -->
  </PropertyGroup>

Ported Version (Relavant Portion):

XML
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <TargetFramework>net5.0-windows</TargetFramework>
    <AssemblyName>System.Windows.Forms.DataVisualization</AssemblyName>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <CLSCompliant>false</CLSCompliant>
    <NoWarn>$(NoWarn);618</NoWarn>
    <UseWindowsForms>true</UseWindowsForms>
    <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
    <DefineConstants>$(DefineConstants);WINFORMS_CONTROL</DefineConstants>
  </PropertyGroup>

You have to pay attention to this directive<UseWindowsForms>true</UseWindowsForms>:

The UseWindowsForms property controls whether or not your application is built to target Windows Forms.

This property alters the MSBuild pipeline to correctly process a Windows Forms project and related files. The default value is false. Set the UseWindowsForms property to true to enable Windows Forms support. You can only target the Windows platform when this setting is enabled (source).

Getting Started with Chart Controls

The best way to learn about Chart Controls is by looking at the sample solution where via interactive experience with the app, you can learn about every chart type and every major feature. While modifying the control parameters and instantly seeing how that affects the look of the control, you can also get the generated C# or Visual Basic code to use in your apps.

Chart Controls

With the sample project, you can see every property and parameters in action:

Sample1

and then copy the relavant portion of the code (C# or VB.NET):

Sample2

History

  • 8th April: Initial porting to .NET 5

Hope this helps!

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Chief Technology Officer
Switzerland Switzerland
Senior Manager with broad experience in all aspects of information technology.
Direct experience with:
- project management and organization
- application architecture/development
- infrastructure and security design/implementation

Senior Security Architect
Senior Technical Information Security Officer

Comments and Discussions

 
QuestionUnable to add Chart control to Toolbox in VB Pin
vmxa6-Feb-22 6:07
vmxa6-Feb-22 6:07 
PraiseHad some issues at the beginning and now it's works awesome. Pin
Edgar Mauricio Diaz Orellana24-Sep-21 5:03
Edgar Mauricio Diaz Orellana24-Sep-21 5:03 
GeneralRe: Had some issues at the beginning and now it's works awesome. Pin
Angelo Cresta24-Sep-21 6:04
professionalAngelo Cresta24-Sep-21 6:04 
GeneralRe: Had some issues at the beginning and now it's works awesome. Pin
Edgar Mauricio Diaz Orellana24-Sep-21 6:29
Edgar Mauricio Diaz Orellana24-Sep-21 6:29 
GeneralRe: Had some issues at the beginning and now it's works awesome. Pin
Edgar Mauricio Diaz Orellana27-Sep-21 7:36
Edgar Mauricio Diaz Orellana27-Sep-21 7:36 
QuestionDesignierter Support under .net5 Pin
Driveman21-Sep-21 22:11
Driveman21-Sep-21 22:11 
AnswerRe: Designierter Support under .net5 Pin
Edgar Mauricio Diaz Orellana27-Sep-21 23:10
Edgar Mauricio Diaz Orellana27-Sep-21 23:10 
QuestionHow do I add a specific chart type (line graph) to my project using this? Pin
David J Bowser19-Aug-21 6:08
David J Bowser19-Aug-21 6:08 
AnswerRe: How do I add a specific chart type (line graph) to my project using this? Pin
greg chu19-Aug-21 6:17
greg chu19-Aug-21 6:17 
AnswerRe: How do I add a specific chart type (line graph) to my project using this? Pin
David J Bowser27-Aug-21 9:02
David J Bowser27-Aug-21 9:02 
QuestionI am trying to get Y Axis with interval 50 starting at 50 going to 400 Pin
Paul M Cohen25-May-21 14:47
Paul M Cohen25-May-21 14:47 
AnswerRe: I am trying to get Y Axis with interval 50 starting at 50 going to 400 Pin
Angelo Cresta26-May-21 0:05
professionalAngelo Cresta26-May-21 0:05 
QuestionWorks perfectly, thank you! Pin
Paula Scholz4-May-21 7:48
Paula Scholz4-May-21 7:48 
AnswerRe: Works perfectly, thank you! Pin
Angelo Cresta4-May-21 9:01
professionalAngelo Cresta4-May-21 9:01 
GeneralRe: Works perfectly, thank you! Pin
Paula Scholz4-May-21 9:06
Paula Scholz4-May-21 9:06 
GeneralRe: Works perfectly, thank you! Pin
Paula Scholz4-May-21 11:58
Paula Scholz4-May-21 11:58 
GeneralRe: Works perfectly, thank you! Pin
Angelo Cresta4-May-21 21:27
professionalAngelo Cresta4-May-21 21:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.