- Create an new window forms application
- This will creates by default Form1
- Go to Tollbox
- Drag and Drop two buttons or double click on Button two times
- This will create two buttons on the form1 as button1 & button2
- Select button1
- Right Click on it
- Select properties
- This will open properties window on the Right side
- In properties set Name as: btnShowBackImage
- In properties set Text as: Show Background Image
- Select the Events option
- Generate the Event Handler for btnShowBackImage button Click Event
Goto Source and write the following code
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 WABasics
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void
btnShowBackImage_Click(object sender, EventArgs e)
{
this.BackgroundImage = Image.FromFile("D:\\Dam.jpg");
this.BackgroundImageLayout=ImageLayout.Zoom;
this.WindowState = FormWindowState.Maximized;
}
}
}
|
- Select Button2
- Right Click on it
- Select properties
- This will open properties window on the Right side
- In properties set Name as: btnHideBackImage
- In properties set Text as: Hide Background Image
- Select the Events option
- Generate the Event Handler for btnHideBackImage button Click Event i.e.,
Goto Source and write the following code
private void btnHideBackImage_Click(object sender, EventArgs
e)
{
this.BackgroundImage = null;
}
|
Result:-
Click on ShowBackGround Image
No comments:
Post a Comment