Selasa, 01 Oktober 2013

How to change Text color using colorDialog in windows form

Introduction : allows the user to pick a color exposed by the Color property of type System.Drawing.Color.

If you want to change TextColor using colorDialog. WinForms ships with several standard dialogs (sometimes known as "common dialogs") provided as components from the System.Windows. Forms namespace. A component is like a control in that you can drag it from the Toolbox onto a design surface and set its properties using the Property Browser. However, unlike a control, a component doesn't render in a region. Instead, it shows up on the tray along the bottom of the design surface so that you can choose it, and it isn't shown at run time at all.

Step-1 : Take a TextBox and button control to the winform.
Step-2 :  Handle Button_click event for generating colorDialog and pick color from colorDialog.

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

        private void button1_Click(object sender, EventArgs e)
        {
            ColorDialog cld = new ColorDialog();
            DialogResult dr = cld.ShowDialog();
            if (dr ==DialogResult .OK)
            {
                textBox1.ForeColor = cld.Color;
           
            }
        }
    }
}

Output
How to change Text color using colorDialog in windows form
How to change Text color using colorDialog in windows form
How to change Text color using colorDialog in windows form



Tidak ada komentar:

Posting Komentar