Example with GroupBox&Panel:-



Add a new Form i.e.,FormGroupPanel to the Windows Application WABasics
Create two labels,one  textboxe and  Eight checkBoxes one Panel,one GroupBox

set the following properties to the checkboxes :-


Label1:
     Text       : Enter AnyData
     Name     : chkSampleData



Label2:
     Text       : ForeColor
     Name     : lblForeColor

groupBox1:
     Text       : BackColor
     Name     : groupBox1

Panel1:
     Name       : panel1
    



checkBox1:
     Text       : Red
     Name     : chkRed


checkBox2:
     Text       : Green
     Name     : chkGreen

checkBox3:
     Text       : Blue
     Name     : chkBlue

checkBox4:
     Text       : White
     Name     : chkWhite




checkBox5:
     Text       : Cyan
     Name     : chkCyan

checkBox6:
     Text       : Gold
     Name     : chkGold

checkBox7:
     Text       : Yellow
     Name     : chkYellow

checkBox8:
     Text       : Black
     Name     : chkBlack


Design :-


Generate theEventHandlers for chkRed,chkGreen,chkBlue,chkWhite,chkCyan,chkGold,chkYellow,chkBlack CheckedChanged Events
& write the following code in Source[FormGroupPanel.cs] 


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 FormGroupPanel : Form
    {
        public FormGroupPanel()
        {
            InitializeComponent();
        }

        private void optRed_CheckedChanged(object sender, EventArgs e)
        {
            txtSample.BackColor = Color.Red;
        }

        private void optGreen_CheckedChanged(object sender, EventArgs e)
        {
            txtSample.BackColor = Color.Green;
        }

        private void optBlue_CheckedChanged(object sender, EventArgs e)
        {
            txtSample.BackColor = Color.Blue;
        }

        private void optWhite_CheckedChanged(object sender, EventArgs e)
        {
            txtSample.BackColor = Color.White;
        }

        private void Cyan_CheckedChanged(object sender, EventArgs e)
        {
            txtSample.ForeColor = Color.Cyan;
        }

        private void optGold_CheckedChanged(object sender, EventArgs e)
        {
            txtSample.ForeColor = Color.Gold;
        }

        private void Yellow_CheckedChanged(object sender, EventArgs e)
        {
            txtSample.ForeColor = Color.Yellow;
        }

        private void optBlack_CheckedChanged(object sender, EventArgs e)
        {
            txtSample.ForeColor = Color.Black;
        }

    }
}



Result :-


No comments:

Post a Comment