//examples with source code to desingn an application with checkbox and adiobutton
public partial class Form6 : Form{
int count = 0;
public Form6()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb = sender as CheckBox;
int amt = int.Parse(txtAmount.Text);
if (cb.Checked)
{
count += 1;
amt += Convert.ToInt32(cb.Tag);
}
else
{
count -= 1;
amt -= Convert.ToInt32(cb.Tag);
}
txtAmount.Text = amt.ToString();
if (count == 0)
radioButton1.Checked = true;
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
int amt = int.Parse(txtAmount.Text);
if (amt > 0)
{
RadioButton rb = sender as RadioButton;
if (rb.Checked)
amt += Convert.ToInt32(rb.Tag);
else
amt -= Convert.ToInt32(rb.Tag);
txtAmount.Text = amt.ToString();
}
else
radioButton1.Checked = true;
}
Showing posts with label c sharp windows forms. Show all posts
Showing posts with label c sharp windows forms. Show all posts
Wednesday, 20 October 2010
examples with source code of how to raise an event
//examples with source code of how to raise an event
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
MessageBox.Show("Event Raised");
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
MessageBox.Show("Event Raised");
Labels:
c sharp windows forms,
c# windows forms
examples with source-code to display where user has clicked
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show("Welcome to windows applications");
}
private void Form1_Click(object sender, EventArgs e)
{
MessageBox.Show("You have clicked on the form");
}
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show("Welcome to windows applications");
}
private void Form1_Click(object sender, EventArgs e)
{
MessageBox.Show("You have clicked on the form");
}
Labels:
c sharp windows forms
Sunday, 22 August 2010
source code or examples of how to use listboxes

//source code or examples of how to use listboxes
//try to develop same form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsProject
{
public partial class Form7 : Form
{
public Form7()
{
InitializeComponent();
}
private void Form7_Load(object sender, EventArgs e)
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsProject
{
public partial class Form7 : Form
{
public Form7()
{
InitializeComponent();
}
private void Form7_Load(object sender, EventArgs e)
{
//source code or examples of how to use listboxes
listBox1.Items.Add("AP");
listBox1.Items.Add("Tamilnadu");
listBox1.Items.Add("Karnataka");
listBox1.Items.Add("Kerala");
listBox1.Items.Add("Orissa");
listBox1.Items.Add("Maharastra");
string[] cols = { "Red", "Blue", "Green", "White", "Black", "Yellow", "Pink" };
checkedListBox1.Items.AddRange(cols);
}
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(Convert.ToInt32(e.KeyChar) == 13)
if(comboBox1.FindString(comboBox1.Text) == -1)
comboBox1.Items.Add(comboBox1.Text);
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.Text);
MessageBox.Show(comboBox1.SelectedIndex.ToString());
MessageBox.Show(comboBox1.SelectedItem.ToString());
}
private void button2_Click(object sender, EventArgs e)
{
foreach(object obj in listBox1.SelectedItems)
MessageBox.Show(obj.ToString());
}
private void button3_Click(object sender, EventArgs e)
{
string str = null;
foreach (object obj in checkedListBox1.CheckedItems)
str += obj.ToString() + ", ";
str = str.Substring(0, str.Length - 2);
int pos = str.LastIndexOf(",");
if (pos != -1)
{
str = str.Remove(pos, 1);
str = str.Insert(pos, " and");
}
MessageBox.Show(str);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
listBox1.Items.Add("AP");
listBox1.Items.Add("Tamilnadu");
listBox1.Items.Add("Karnataka");
listBox1.Items.Add("Kerala");
listBox1.Items.Add("Orissa");
listBox1.Items.Add("Maharastra");
string[] cols = { "Red", "Blue", "Green", "White", "Black", "Yellow", "Pink" };
checkedListBox1.Items.AddRange(cols);
}
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(Convert.ToInt32(e.KeyChar) == 13)
if(comboBox1.FindString(comboBox1.Text) == -1)
comboBox1.Items.Add(comboBox1.Text);
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.Text);
MessageBox.Show(comboBox1.SelectedIndex.ToString());
MessageBox.Show(comboBox1.SelectedItem.ToString());
}
private void button2_Click(object sender, EventArgs e)
{
foreach(object obj in listBox1.SelectedItems)
MessageBox.Show(obj.ToString());
}
private void button3_Click(object sender, EventArgs e)
{
string str = null;
foreach (object obj in checkedListBox1.CheckedItems)
str += obj.ToString() + ", ";
str = str.Substring(0, str.Length - 2);
int pos = str.LastIndexOf(",");
if (pos != -1)
{
str = str.Remove(pos, 1);
str = str.Insert(pos, " and");
}
MessageBox.Show(str);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
Subscribe to:
Posts (Atom)