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
Solved

How to open colordialog multiple times in ConsoleApp

Posted on 2009-07-13
8
269 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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:…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

839 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