Solved

How to open colordialog multiple times in ConsoleApp

Posted on 2009-07-13
8
265 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

13 Experts available now in Live!

Get 1:1 Help Now