Sunday, 25 December 2011

Get List Of All Printers


To Getting List of All Printers First of all add a namespace
System.Drawing.Printing

use Foreach Loop:

foreach(string printer in PrinterSettings.InstalledPrinters)
{
Combobox1.Items.Add(Printer.ToString());
}

using this you get list of all printer install on your system

Saturday, 24 December 2011

Select Second Maximum From a Table in Sql

Q.Find Second Maximum From a Table in Sql

select max(duration) from course where duration<(select max(duration) from course)

OR



select min(duration) from course where duration in(select top 2 duration from course)

Wednesday, 7 December 2011

EditTable Listbox


To create a edittable list box take a list box and enter items in it.now select the list box double click event from event list.

private void listBox1_DoubleClick(object sender, EventArgs e)
{
//get list item index
int itemno = this.listBox1.SelectedIndex;
//get list item tex;
string itemvalue = this.listBox1.Items[itemno].ToString();
Rectangle rect = this.listBox1.GetItemRectangle(itemno);
this.textBox1.BackColor = Color.Aqua;
this.textBox1.BorderStyle = BorderStyle.Fixed3D;
//get list item drawing point
this.textBox1.Location = new System.Drawing.Point(rect.X + 12, rect.Y + 12);
this.textBox1.Size = new System.Drawing.Size(rect.Width + 5, rect.Height - 5);
this.textBox1.Visible = true;
this.textBox1.Text = itemvalue;
this.textBox1.Focus();
this.textBox1.SelectAll();
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
//if User Press Enter button
if (e.KeyChar == 13)
{
this.listBox1.Items[this.listBox1.SelectedIndex] = this.textBox1.Text;
this.textBox1.Visible = false;
}
//If User press Escape button
if (e.KeyChar == 27)
{

this.textBox1.Visible = false;
}
}