Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to open colordialog multiple times in ConsoleApp

Posted on 2009-07-13
8
Medium Priority
?
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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
 

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 1500 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

722 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