C# WPF Forms in VS2019 Community
________________________________________________
Thanks for checking out my posting.
Check out the latest at https://mrobvious.wordpress.com No scraping please…..
________________________________________________
Form1.cs <—- the csharp code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsCsharpApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Declare variables here
public double dbl_in1;
public double dbl_in2;
public double dbl_output3;
private void button1add_Click(object sender, EventArgs e)
{
double.TryParse(textBoxInput1.Text, out dbl_in1);
double.TryParse(textBoxInput2.Text, out dbl_in2);
dbl_output3 = dbl_in1 + dbl_in2;
textBoxOutput3.Text = dbl_output3.ToString();
if (dbl_output3 == 5)
textBoxOutput3.BackColor = Color.FromArgb(0, 255, 255);
else
textBoxOutput3.BackColor = Color.FromArgb(255, 255, 0);
switch (dbl_output3)
{
case (0 ):
textBoxOutput3.BackColor = Color.FromArgb(255, 0, 0);
break;
case 2.0:
textBoxOutput3.BackColor = Color.FromArgb(0, 255, 0);
break;
case 4.0:
textBoxOutput3.BackColor = Color.FromArgb(0, 0, 255);
break;
}
int a = 0;
int b = 255;
while (a < b)
{
a++;
//
Console.WriteLine(a);
Graphics g;
g = this.CreateGraphics();
Pen myPen = new Pen(Color.FromArgb(a, 100, 100));
myPen.Width = 1;
g.DrawLine(myPen, 30, a, 45, 65);
g.DrawLine(myPen, 1, a+10, 45, 65);
}
}
private void button2clear_Click(object sender, EventArgs e)
{
dbl_in1 = 0.0;
dbl_in2 = 0.0;
dbl_output3 = 0.0;
textBoxInput1.Text = “”;
textBoxInput2.Text = “”;
textBoxOutput3.Text = “”;
textBoxOutput3.BackColor = Color.FromArgb(255, 255, 255);
}
}
}
______________________________________________
Form1.Designer.cs <——–
/// This file you’d normally see as toolbox object graphics like Button and textBox in VS
/// You’re seeing it as text because I left clicked on the file in Windows Explorer and
///rightmouse “edit” which opened it in notepad
namespace WindowsFormsCsharpApp1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name=”disposing”>true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support – do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBoxInput1 = new System.Windows.Forms.TextBox();
this.textBoxInput2 = new System.Windows.Forms.TextBox();
this.textBoxOutput3 = new System.Windows.Forms.TextBox();
this.button1add = new System.Windows.Forms.Button();
this.labelInput1 = new System.Windows.Forms.Label();
this.labelInput2 = new System.Windows.Forms.Label();
this.labelOutput3 = new System.Windows.Forms.Label();
this.button2clear = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxInput1
//
this.textBoxInput1.Location = new System.Drawing.Point(166, 83);
this.textBoxInput1.Name = “textBoxInput1”;
this.textBoxInput1.Size = new System.Drawing.Size(100, 22);
this.textBoxInput1.TabIndex = 0;
//
// textBoxInput2
//
this.textBoxInput2.Location = new System.Drawing.Point(166, 122);
this.textBoxInput2.Name = “textBoxInput2”;
this.textBoxInput2.Size = new System.Drawing.Size(100, 22);
this.textBoxInput2.TabIndex = 1;
//
// textBoxOutput3
//
this.textBoxOutput3.Location = new System.Drawing.Point(166, 244);
this.textBoxOutput3.Name = “textBoxOutput3”;
this.textBoxOutput3.Size = new System.Drawing.Size(100, 22);
this.textBoxOutput3.TabIndex = 2;
//
// button1add
//
this.button1add.Location = new System.Drawing.Point(304, 303);
this.button1add.Name = “button1add”;
this.button1add.Size = new System.Drawing.Size(75, 23);
this.button1add.TabIndex = 3;
this.button1add.Text = “Add”;
this.button1add.UseVisualStyleBackColor = true;
this.button1add.Click += new System.EventHandler(this.button1add_Click);
//
// labelInput1
//
this.labelInput1.AutoSize = true;
this.labelInput1.Location = new System.Drawing.Point(55, 87);
this.labelInput1.Name = “labelInput1”;
this.labelInput1.Size = new System.Drawing.Size(51, 17);
this.labelInput1.TabIndex = 4;
this.labelInput1.Text = “Input 1”;
//
// labelInput2
//
this.labelInput2.AutoSize = true;
this.labelInput2.Location = new System.Drawing.Point(55, 127);
this.labelInput2.Name = “labelInput2”;
this.labelInput2.Size = new System.Drawing.Size(51, 17);
this.labelInput2.TabIndex = 5;
this.labelInput2.Text = “Input 2”;
//
// labelOutput3
//
this.labelOutput3.AutoSize = true;
this.labelOutput3.Location = new System.Drawing.Point(55, 249);
this.labelOutput3.Name = “labelOutput3”;
this.labelOutput3.Size = new System.Drawing.Size(59, 17);
this.labelOutput3.TabIndex = 6;
this.labelOutput3.Text = “Output3”;
//
// button2clear
//
this.button2clear.Location = new System.Drawing.Point(404, 303);
this.button2clear.Name = “button2clear”;
this.button2clear.Size = new System.Drawing.Size(75, 23);
this.button2clear.TabIndex = 7;
this.button2clear.Text = “Clear”;
this.button2clear.UseVisualStyleBackColor = true;
this.button2clear.Click += new System.EventHandler(this.button2clear_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.button2clear);
this.Controls.Add(this.labelOutput3);
this.Controls.Add(this.labelInput2);
this.Controls.Add(this.labelInput1);
this.Controls.Add(this.button1add);
this.Controls.Add(this.textBoxOutput3);
this.Controls.Add(this.textBoxInput2);
this.Controls.Add(this.textBoxInput1);
this.Name = “Form1”;
this.Text = “Form1”;
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox textBoxInput1;
private System.Windows.Forms.TextBox textBoxInput2;
private System.Windows.Forms.TextBox textBoxOutput3;
private System.Windows.Forms.Button button1add;
private System.Windows.Forms.Label labelInput1;
private System.Windows.Forms.Label labelInput2;
private System.Windows.Forms.Label labelOutput3;
private System.Windows.Forms.Button button2clear;
}
}