using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ManipulacaoSimbolica
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtValor;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btAtribuirValor;
//private System.Windows.Forms.Button btCirculo;
private int iTop = 0;
private int iLeft = 0;
private int iValorDaSoma = 0;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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.txtValor = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.btAtribuirValor = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtValor
//
this.txtValor.Location = new System.Drawing.Point(40, 16);
this.txtValor.Name = "txtValor";
this.txtValor.TabIndex = 0;
this.txtValor.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(32, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Valor";
//
// btAtribuirValor
//
this.btAtribuirValor.Location = new System.Drawing.Point(152, 16);
this.btAtribuirValor.Name = "btAtribuirValor";
this.btAtribuirValor.Size = new System.Drawing.Size(144, 23);
this.btAtribuirValor.TabIndex = 2;
this.btAtribuirValor.Text = "Criar Circulo com o valor";
this.btAtribuirValor.Click += new System.EventHandler(this.btAtribuirValor_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(376, 347);
this.Controls.Add(this.btAtribuirValor);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtValor);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btAtribuirValor_Click(object sender, System.EventArgs e)
{
if (txtValor.Text != "")
{
//instanciar novo circulo com o valor em txtValor.
System.Windows.Forms.Button btCirculo = new Button();
//Contando que o valor inserido em txtValor é um numérico inteiro.
btCirculo.Tag = txtValor.Text;
btCirculo.Text = txtValor.Text;
btCirculo.Click +=new EventHandler(btCirculo_Click);
btCirculo.Paint +=new PaintEventHandler(btCirculo_Paint);
btCirculo.Top = 50+iTop;
btCirculo.Left = 50+iLeft;
this.Controls.Add(btCirculo);
iTop++;
iLeft +=35;
}
else
{
MessageBox.Show("Insira um valor");
}
}
private void btCirculo_Click(object sender, EventArgs e)
{
iValorDaSoma += int.Parse(((Button)sender).Tag.ToString());
//MessageBox.Show(iValorDaSoma.ToString());
//Criar novo circulo com o resultado da soma;
System.Windows.Forms.Button btResultado = new Button();
btResultado.Tag = iValorDaSoma.ToString();
btResultado.Text = iValorDaSoma.ToString();
btResultado.Click +=new EventHandler(btResultado_Click);
btResultado.Paint +=new PaintEventHandler(btResultado_Paint);
btResultado.Top = 50+iTop;
btResultado.Left = 50+iLeft;
this.Controls.Add(btResultado);
iTop++;
iLeft +=35;
}
private void btCirculo_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath myGraphicsPath = new
System.Drawing.Drawing2D.GraphicsPath();
myGraphicsPath.AddEllipse(new Rectangle(0, 0, 30, 30));
((Button)sender).BackColor = Color.Chartreuse;
((Button)sender).Size = new System.Drawing.Size(35, 35);
((Button)sender).Region = new Region(myGraphicsPath);
}
private void btResultado_Click(object sender, EventArgs e)
{
MessageBox.Show(((Button)sender).Tag.ToString());
}
private void btResultado_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath myGraphicsPath = new
System.Drawing.Drawing2D.GraphicsPath();
myGraphicsPath.AddEllipse(new Rectangle(0, 0, 30, 30));
((Button)sender).BackColor = Color.Red;
((Button)sender).Size = new System.Drawing.Size(35, 35);
((Button)sender).Region = new Region(myGraphicsPath);
}
}
}