Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

8a - First Windows 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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

/// <summary>
/// this is called when the button is clicked
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("hello world");

}
}
}
8b - Buttons and Forms

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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
MessageBox.Show("hello from button 1");
button2.Visible = true;
}

private void button2_Click(object sender, EventArgs e)


{
MessageBox.Show("hello from button 2");

}
}
}
8c - TextBox.

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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
textBox1.Text = DateTime.Now.ToString();

private void button2_Click(object sender, EventArgs e)


{
MessageBox.Show(textBox1.Text);
}
}
}
8d - CheckBox.

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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Do_checked();

}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
Do_checked();

private void Do_checked()


{
button1.Enabled = checkBox1.Checked;

}
}
8e-RadioButton.

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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void groupBox1_Enter(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
string sColor = "";
if (radioButton1.Checked)
{
sColor = radioButton1.Text;
}

if (radioButton2.Checked)
{
sColor = radioButton2.Text;
}

if (radioButton3.Checked)
{
sColor = radioButton3.Text;
}

MessageBox.Show(sColor);

private void button2_Click(object sender, EventArgs e)


{
Getcolor(radioButton4);
Getcolor(radioButton5);
Getcolor(radioButton6);
}

private void Getcolor(RadioButton rdoButton)


{
if (rdoButton.Checked)
{
MessageBox.Show(rdoButton.Text);
}
}

}
}

8f-TabControl.

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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void tabPage1_Click(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
MessageBox.Show("button from view 1 has been clicked !!!");
}

private void button2_Click(object sender, EventArgs e)


{
MessageBox.Show("button from view 2 has been clicked !!!");

}
}
}

8g- Open-and-Save-Image

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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
Image file;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
OpenFileDialog f = new OpenFileDialog();
f.Filter = "JPG(*.JPG)|*.jpg";
if (f.ShowDialog() == DialogResult.OK)
{
file = Image.FromFile(f.FileName);
pictureBox1.Image = file;
}
}
private void button2_Click(object sender, EventArgs e)
{
SaveFileDialog f = new SaveFileDialog();
f.Filter = "JPG(*.JPG)|*.jpg";
if (f.ShowDialog() == DialogResult.OK)
{
file.Save(f.FileName);
}

private void button2_Click_1(object sender, EventArgs e)


{

}
}

You might also like