Android Tutorial , Programming Tutorial, Php Tutorial, Learn Android, HTML Tutorial, Coding , Java Tutorial, GTU Programs, Learning Programming

Showing posts with label C-Sharp Tutorial. Show all posts
Showing posts with label C-Sharp Tutorial. Show all posts

Wednesday, 26 October 2016

How to use Color Dialog Box in C#

In this example, we are learning that how to use color dialog box control in c#.

First of all , we need to add Color Dialog Control in the form. In this example, one multi line textbox and two buttons were added in the form.



After adding the control, we are learning that how to change background color of textbox using color dialog box and also change font color of textbox.

When you click on the button color dialog box will be open and then you choose color. After selecting color, color will be change of textbox background color and font color.

Let's see the example :



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void background_color_Click(object sender, EventArgs e)
        {
            ColorDialog colorDlg = new ColorDialog();
            colorDlg.AllowFullOpen = true;
            colorDlg.AnyColor = true;
            colorDlg.SolidColorOnly = false;
            colorDlg.Color = Color.Red;
            if (colorDlg.ShowDialog() == DialogResult.OK)
            {
                textBox1.BackColor = colorDlg.Color;
            }
        }

        private void font_color_Click(object sender, EventArgs e)
        {
            ColorDialog colorDlg = new ColorDialog();
            colorDlg.AllowFullOpen = true;
            colorDlg.AnyColor = true;
            colorDlg.SolidColorOnly = false;
            colorDlg.Color = Color.Red;
            if (colorDlg.ShowDialog() == DialogResult.OK)
            {
                textBox1.ForeColor = colorDlg.Color;
            }
        }
    }
}

Output:

ColorDialogBox1

ColorDialogBox

Saturday, 22 October 2016

Add text from textbox in listbox Column in C#

In this example, We are learning how to add items in listbox from textbox on button click.

Let's see the example :

File Name : Form1.cs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Item_Add_ListBox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            item_listbox.Items.Add(txt_item_add.Text);
            txt_item_add.Text = "";
            
            //item_listbox = name of listbox
            //txt_item_add = name of textbox


        }
    }
}

Output :

Listbox add item

ListBox Item add



Like us on Facebook

Categories

Site Visitor

Powered by Blogger.