Solved

How to open colordialog multiple times in ConsoleApp

Posted on 2009-07-13
8
272 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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…

617 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