How to work with ColorDialog in C#.Net(windows application)?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    How to work with ColorDialog in C#.Net(windows application)?

    hai all,

    i have a textbox, if i click it, the color dialog opens, after that if i select a color in that and i press ok or double click color, particular color code should be displayed in the text box in which i have clicked.
    kindly help me with thew sample code.
    Thanx in advance
    With Cheers
    Nirmal
  • PareshRathod
    New Member
    • Mar 2007
    • 28

    #2
    Hi Guy,

    ColorDialog returns the result as datatype...Syst em.Drawing.Colo r
    You can use static method of class
    system.Drawing. ColorTranslator
    ToHtml, ToOle or ToWin32 as per your requirement..

    Hope this will help...

    Paresh

    Originally posted by nirmalsingh
    hai all,

    i have a textbox, if i click it, the color dialog opens, after that if i select a color in that and i press ok or double click color, particular color code should be displayed in the text box in which i have clicked.
    kindly help me with thew sample code.
    Thanx in advance
    With Cheers
    Nirmal

    Comment

    • nirmalsingh
      New Member
      • Sep 2006
      • 218

      #3
      Originally posted by PareshRathod
      Hi Guy,

      ColorDialog returns the result as datatype...Syst em.Drawing.Colo r
      You can use static method of class
      system.Drawing. ColorTranslator
      ToHtml, ToOle or ToWin32 as per your requirement..

      Hope this will help...

      Paresh
      how do i catch the click event of color dialog?

      Comment

      • Shashi Sadasivan
        Recognized Expert Top Contributor
        • Aug 2007
        • 1435

        #4
        do u want to make the control behave in a different way?

        The ColorDialog is an independant control which has ben created so that the user can select a colour and it then returns the colour type.

        If you want to make any changes inbetween this you have to make your own control inheriting from the ColorDialog

        Comment

        • PareshRathod
          New Member
          • Mar 2007
          • 28

          #5
          Why do u want to catch the click event of colordialog?

          Originally posted by nirmalsingh
          how do i catch the click event of color dialog?

          Comment

          • nirmalsingh
            New Member
            • Sep 2006
            • 218

            #6
            Originally posted by PareshRathod
            Why do u want to catch the click event of colordialog?
            if i click cancel, the action should be cancelled. but a color is set in the text box



            Code:
            private void txtSLForeColor_Click(object sender, EventArgs e)
                    {
                        try
                        {
                            cdColorPallette.ShowDialog();
                            txtSLForeColor.Text = cdColorPallette.Color.ToArgb().ToString("x");
                            txtSLForeColor.BackColor = cdColorPallette.Color;
                        }
                        catch (Exception ex)
                        {
                            General.writeErrorLog(this.Name, "txtSLForeColor_Click()", ex.Message);
                        }
                    }

            Comment

            • JnrJnr
              New Member
              • Oct 2009
              • 88

              #7
              Yes I have the same porblem. When choosing cancel, it selects the default color
              ...no wait

              if (colorDialog.Sh owDialog() == DialogResult.OK )

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                .ShowDialog() always returns an instance of DialogResult.
                For the pre-made dialogs (ColorDialog, OpenDialog, SaveDialog, etc) it is always DialogResult.OK or DialogResult.Ca ncel

                Comment

                Working...