Z
zydjohn
Guest
Hello:
Today, I upgraded Visual Studio 2019 to version 16.8.0, which I can target to .NET 5.0 on Windows 10.
I created one Windows Forms App (.Net) project called “ToggleSwitchForms”.
I changes the project to target .NET 5.0 and added reference to
“PresentationCore.dll” and “PresentationFramework.dll” from .net 5.0 package folder in Windows.
The following is my code:
using System;
using System.Drawing;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
namespace ToggleSwitchForms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ToggleButton button1 = new ToggleButton
{
Style = new Style { TargetType = typeof(Rectangle) },
Height = 50,
Width = 100,
Content = "Text",
};
Controls.Add(button1);
}
}
}
I got compiler errors:
Error CS1503 Argument 1: cannot convert from 'System.Windows.Controls.Primitives.ToggleButton' to 'System.Windows.Forms.Control'
CS7069 DependencyObject claims it is based in WindowsBase but it can't be found.
I don’t understand the meaning of the compiler errors, and I think the ToggleSwitch button seems to be totally different from the ToggleSwitch button as I understand.
I think I need one ToggleSwitch button with the following properties:
Location(x,y), Size(x,y), ActiveText, InActiveText, ActiveColor, InActiveColor, Visible.
Please share some example code on how to create a ToggleSwitch button, which I can set up the above properties.
Continue reading...
Today, I upgraded Visual Studio 2019 to version 16.8.0, which I can target to .NET 5.0 on Windows 10.
I created one Windows Forms App (.Net) project called “ToggleSwitchForms”.
I changes the project to target .NET 5.0 and added reference to
“PresentationCore.dll” and “PresentationFramework.dll” from .net 5.0 package folder in Windows.
The following is my code:
using System;
using System.Drawing;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
namespace ToggleSwitchForms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ToggleButton button1 = new ToggleButton
{
Style = new Style { TargetType = typeof(Rectangle) },
Height = 50,
Width = 100,
Content = "Text",
};
Controls.Add(button1);
}
}
}
I got compiler errors:
Error CS1503 Argument 1: cannot convert from 'System.Windows.Controls.Primitives.ToggleButton' to 'System.Windows.Forms.Control'
CS7069 DependencyObject claims it is based in WindowsBase but it can't be found.
I don’t understand the meaning of the compiler errors, and I think the ToggleSwitch button seems to be totally different from the ToggleSwitch button as I understand.
I think I need one ToggleSwitch button with the following properties:
Location(x,y), Size(x,y), ActiveText, InActiveText, ActiveColor, InActiveColor, Visible.
Please share some example code on how to create a ToggleSwitch button, which I can set up the above properties.
Continue reading...