Solved

How to open colordialog multiple times in ConsoleApp

Posted on 2009-07-13
8
262 Views
Last Modified: 2013-12-17
Hello All,

The ColorDialogue is to invoke multipletimes in my console app,but  the same is working in forms.
Can u suggest me how to invoke the colordialoge multiple times. Please check the code.
String^ Colour()

{

	String^ str = String::Empty;

	ColorDialog^ colorDialogue =gcnew ColorDialog();

	try

	{

		

		colorDialogue->AllowFullOpen =true;

		colorDialogue->AnyColor = true;
 

		if(colorDialogue->ShowDialog() ==::DialogResult::OK)

		{

			str =  colorDialogue->Color.ToString();

		}

		

	}

	finally

	{

		if(nullptr!=colorDialogue)

		{

			delete colorDialogue;

			colorDialogue=nullptr;

		}

	}

	return str;
 

}
 

Client
 

String^ str1 =Colour(); //First time it is opening

String^ str2=Colour();//Not opening

Open in new window

0
Comment
Question by:vishnu_kavalakuntla
  • 5
  • 3
8 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 24838746
The code looks OK.
(I think the finally block is redundant but it should not cause problems).

I don't see why it should not work.


You could give this a try
String^ Colour()
{
        ColorDialog^ colorDialogue =gcnew ColorDialog();
        try
        {
               
                colorDialogue->AllowFullOpen =true;
                colorDialogue->AnyColor = true;
 
                if(colorDialogue->ShowDialog() ==::DialogResult::OK)
                {
                       return  colorDialogue->Color.ToString();
                }
               
        }
        finally
        {
                if(nullptr!=colorDialogue)
                {
                        delete colorDialogue;
                        colorDialogue=nullptr;
                }
        }
        return String::Empty;;
 
}

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 24838751
To much copied

You could give this a try
String^ Colour()
{
        ColorDialog^ colorDialogue =gcnew ColorDialog();
        try
        {
               
                colorDialogue->AllowFullOpen =true;
                colorDialogue->AnyColor = true;
 
                if(colorDialogue->ShowDialog() ==::DialogResult::OK)
                {
                       return  colorDialogue->Color.ToString();
                }
               
        }
          return String::Empty;;
 
}

   

0
 

Author Comment

by:vishnu_kavalakuntla
ID: 24839468
Hello Andy,

the above solution is like this.

String^ Colour()
{
String^ str =String::Empty;
       ColorDialog^ colorDialogue =gcnew ColorDialog();
       try
       {
               
               colorDialogue->AllowFullOpen =true;
               colorDialogue->AnyColor = true;

                if(colorDialogue->ShowDialog() ==::DialogResult::OK)
               {
                     str= colorDialogue->Color.ToString();
               }
               
       }
       finally
       {
               if(nullptr!=colorDialogue)
               {
                       delete colorDialogue;
                       colorDialogue=nullptr;
               }
       }
       return str;

}



Please check the above code.

Open in new window

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 24839577
Isn't that what you posted initially and said did not work?

If it does not work have you tried my suggested code ?  (I don't see any obvious mistake in your code but if it doesn't work then it does not work ! )
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:vishnu_kavalakuntla
ID: 24856567
It is not working.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 24856733
>>It is not working.

What?
The code you posted with the comment the above solution is like this?
My suggestion?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 24859839
I've just done a simple console app.
Your code functions - I see the color dialog twice.

Using the following I also see the color dialog twice:

String^ Colour()
{

       ColorDialog^ colorDialogue =gcnew ColorDialog();
       try
       {
               
               colorDialogue->AllowFullOpen =true;
               colorDialogue->AnyColor = true;

                if(colorDialogue->ShowDialog() ==::DialogResult::OK)
               {
                      return  colorDialogue->Color.ToString();
               }
               
       }
       catch(Exception^ e)
       {
       }
         return String::Empty;;

 
}

int main(array<System::String ^> ^args)
{
String^ str1 =Colour(); //First time it is opening
String^ str2=Colour();//Again the colour dialog opens
return 0;  //breakpoint here - str1 and str2 containing DIFFERENT values based on what I have selected
}


0
 

Author Closing Comment

by:vishnu_kavalakuntla
ID: 31602765
Thanks Andy. Now it is working fine. I think it is working previously too may be. Any How Thank you for your response every time. Thanks a lot.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now