• Revista PROGRAMAR: Já está disponível a edição #53 da revista programar. Faz já o download aqui!

will09

[C#] Programa exemplo de ComboBox e radioButton

1 mensagem neste tópico

Bem aqui um pequeno programa para exemplificar o uso de radioButtons =)

Espero qu ajude para quem precisar.

/*
* Created by SharpDevelop.
* User: aluno
* Date: 31-10-2006
* Time: 9:01
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Forms;

namespace exemploformsPSI
{
/// <summary>
/// Description of MainForm.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
	private System.Windows.Forms.Label label1;
	private System.Windows.Forms.RadioButton radioButton3;
	private System.Windows.Forms.GroupBox groupBox1;
	private System.Windows.Forms.RadioButton radioButton1;
	private System.Windows.Forms.RadioButton radioButton4;
	private System.Windows.Forms.TextBox textBox1;
	private System.Windows.Forms.Button button1;
	private System.Windows.Forms.RadioButton radioButton2;
	public MainForm()
	{
		//
		// The InitializeComponent() call is required for Windows Forms designer support.
		//
		InitializeComponent();

		//
		// TODO: Add constructor code after the InitializeComponent() call.
		//
	}

	[sTAThread]
	public static void Main(string[] args)
	{
		Application.Run(new MainForm());
	}

	#region Windows Forms Designer generated code
	/// <summary>
	/// This method is required for Windows Forms designer support.
	/// Do not change the method contents inside the source code editor. The Forms designer might
	/// not be able to load this method if it was changed manually.
	/// </summary>
	private void InitializeComponent() {
		System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
		this.radioButton2 = new System.Windows.Forms.RadioButton();
		this.button1 = new System.Windows.Forms.Button();
		this.textBox1 = new System.Windows.Forms.TextBox();
		this.radioButton4 = new System.Windows.Forms.RadioButton();
		this.radioButton1 = new System.Windows.Forms.RadioButton();
		this.groupBox1 = new System.Windows.Forms.GroupBox();
		this.radioButton3 = new System.Windows.Forms.RadioButton();
		this.label1 = new System.Windows.Forms.Label();
		this.groupBox1.SuspendLayout();
		this.SuspendLayout();
		//
		// radioButton2
		//
		this.radioButton2.Location = new System.Drawing.Point(16, 56);
		this.radioButton2.Name = "radioButton2";
		this.radioButton2.Size = new System.Drawing.Size(120, 16);
		this.radioButton2.TabIndex = 1;
		this.radioButton2.Text = "11 a 20 Anos";
		this.radioButton2.Click += new System.EventHandler(this.RadioButton1Click);
		//
		// button1
		//
		this.button1.BackColor = System.Drawing.Color.DeepSkyBlue;
		this.button1.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
		this.button1.Location = new System.Drawing.Point(200, 192);
		this.button1.Name = "button1";
		this.button1.Size = new System.Drawing.Size(40, 32);
		this.button1.TabIndex = 2;
		this.button1.Text = "OK";
		this.button1.Click += new System.EventHandler(this.Button1Click);
		//
		// textBox1
		//
		this.textBox1.AcceptsTab = true;
		this.textBox1.AutoSize = false;
		this.textBox1.BackColor = System.Drawing.Color.DodgerBlue;
		this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
		this.textBox1.Font = new System.Drawing.Font("Arial Black", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
		this.textBox1.ForeColor = System.Drawing.Color.Chartreuse;
		this.textBox1.Location = new System.Drawing.Point(200, 48);
		this.textBox1.Name = "textBox1";
		this.textBox1.Size = new System.Drawing.Size(360, 128);
		this.textBox1.TabIndex = 3;
		this.textBox1.Text = "Idade";
		this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
		this.textBox1.Visible = false;
		//
		// radioButton4
		//
		this.radioButton4.Location = new System.Drawing.Point(16, 120);
		this.radioButton4.Name = "radioButton4";
		this.radioButton4.Size = new System.Drawing.Size(120, 16);
		this.radioButton4.TabIndex = 3;
		this.radioButton4.Text = "61 a 120+ Anos";
		this.radioButton4.Click += new System.EventHandler(this.RadioButton1Click);
		//
		// radioButton1
		//
		this.radioButton1.Location = new System.Drawing.Point(16, 24);
		this.radioButton1.Name = "radioButton1";
		this.radioButton1.Size = new System.Drawing.Size(120, 16);
		this.radioButton1.TabIndex = 0;
		this.radioButton1.Text = "1 a 10 Anos";
		this.radioButton1.Click += new System.EventHandler(this.RadioButton1Click);
		//
		// groupBox1
		//
		this.groupBox1.Controls.Add(this.radioButton4);
		this.groupBox1.Controls.Add(this.radioButton3);
		this.groupBox1.Controls.Add(this.radioButton2);
		this.groupBox1.Controls.Add(this.radioButton1);
		this.groupBox1.Location = new System.Drawing.Point(24, 80);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Size = new System.Drawing.Size(152, 152);
		this.groupBox1.TabIndex = 0;
		this.groupBox1.TabStop = false;
		this.groupBox1.Text = "Idades";
		//
		// radioButton3
		//
		this.radioButton3.Location = new System.Drawing.Point(16, 88);
		this.radioButton3.Name = "radioButton3";
		this.radioButton3.Size = new System.Drawing.Size(120, 16);
		this.radioButton3.TabIndex = 2;
		this.radioButton3.Text = "21 a 60 Anos";
		this.radioButton3.Click += new System.EventHandler(this.RadioButton1Click);
		//
		// label1
		//
		this.label1.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
		this.label1.Location = new System.Drawing.Point(16, 48);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(160, 24);
		this.label1.TabIndex = 1;
		this.label1.Text = "Selecione a sua idade?";
		//
		// MainForm
		//
		this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
		this.BackColor = System.Drawing.Color.SteelBlue;
		this.ClientSize = new System.Drawing.Size(608, 280);
		this.Controls.Add(this.textBox1);
		this.Controls.Add(this.button1);
		this.Controls.Add(this.label1);
		this.Controls.Add(this.groupBox1);
		this.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
		this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
		this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
		this.Name = "MainForm";
		this.Text = "ExmploForm PSI 11ºA CTGPSI - EPRM";
		this.Closing += new System.ComponentModel.CancelEventHandler(this.MainFormClosing);
		this.groupBox1.ResumeLayout(false);
		this.ResumeLayout(false);
	}
	#endregion
	void MainFormClosing(object sender, System.ComponentModel.CancelEventArgs e)
	{
		MessageBox.Show("Produzido por Jorge Colaco aka wiLL");
	}

	void Button1Click(object sender, System.EventArgs e)
	{
		if (radioButton1.Checked)
		{
			textBox1.Visible = true;
			textBox1.Text = "1-10 Anos \n Es Novinho";
		}
		else if (radioButton2.Checked)
		{
			textBox1.Visible = true;
			textBox1.Text = "11-20 Anos \n Teenager";
		}
		else if (radioButton3.Checked)
		{
			textBox1.Visible = true;
			textBox1.Text = "21-60 Anos \n Meia Idade";
		}
		else if (radioButton4.Checked)
		{
			textBox1.Visible = true;
			textBox1.Text = "61-120+ Anos \n Velhote";
		}
		else
		{
			textBox1.Visible = true;
			textBox1.Text = "Selecione uma opccao";
		}
	}


	void RadioButton1Click(object sender, System.EventArgs e)
	{
		textBox1.Visible = false;
	}

}
}

Desta vez pus o código todo, é sempre bom para comparar classes e habituar-nos a elas.

PEACE

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Crie uma conta ou ligue-se para comentar

Só membros podem comentar

Criar nova conta

Registe para ter uma conta na nossa comunidade. É fácil!


Registar nova conta

Entra

Já tem conta? Inicie sessão aqui.


Entrar Agora