.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

message box

Posted By: kamlesh     Posted Date: February 07, 2011    Points:2   Category :Windows Application
Hi
i have Created One Application in that i used YES NO CANCEL Message Box and i used

if (Res == System.Windows.Forms.DialogResult.Yes)
{
IsNeedtoMarge = false;
}
else if (Res == System.Windows.Forms.DialogResult.No)
{
IsNeedtoMarge = true;
}
else if (Res == System.Windows.Forms.DialogResult.Cancel)
{
// What code should i write Here so i will exit
}


i want when i select cancel so it should exit from the code ....


Thanks
Kamlesh Nikam

Responses
Author: shankey             
Posted Date: February 07, 2011     Points: 5   

hi,

I am not clear what you want to do on click of cancel button but it looks that you dont want any action to be taken. Just to skip the rest of the code written after your else if (... == cancel) condition should be passed away can be achived by writing return statement or you can set a flag inside the else if block of cancel section to identify what to do.

Shankey
Author: krishana singh             
Posted Date: February 16, 2011     Points: 5   

using ascii code of escape key...

Author: Maverick             
Posted Date: February 28, 2011     Points: 20   

Hello just write "End" there

i have Created One Application in that i used YES NO CANCEL Message Box and i used

if (Res == System.Windows.Forms.DialogResult.Yes)
{
IsNeedtoMarge = false;
}
else if (Res == System.Windows.Forms.DialogResult.No)
{
IsNeedtoMarge = true;
}
else if (Res == System.Windows.Forms.DialogResult.Cancel)
{
End OR Application.exit()
}


Thanks,
Maverick
Author: kamlesh             
Posted Date: March 08, 2011     Points: 20   

public class clsError
{
static string ErrorLogPath = AppDomain.CurrentDomain.BaseDirectory + "ErrorLog.txt";
static string ErrorBackupPath=AppDomain.CurrentDomain.BaseDirectory + "ErrorBackup";
public static void LogError(string ErrorMessage, Exception ex , string ClassName , string FunctionName )
{
// Write the string to a file.
StreamWriter file = null;
bool IsBackupTaken = false;
try
{
FileInfo f;
//Checks Backup folder exist if not then creats Folder
if (!Directory.Exists(ErrorBackupPath))
Directory.CreateDirectory(ErrorBackupPath);
//Takes Backup if existing file is not of current day.
if (File.Exists(ErrorLogPath))
{
f = new FileInfo(ErrorLogPath);
if (f.CreationTime.DayOfYear != System.DateTime.Now.DayOfYear)
{
File.Move(ErrorLogPath, ErrorBackupPath + "ErrorLog" + System.DateTime.Now.ToString("yyyy-MM-dd_HHmmss") + ".txt");
IsBackupTaken = true;
}
}

//Write Error Log in File
string ErrorLog = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " : " + ErrorMessage;
if (ClassName.Trim() != "" || FunctionName.Trim() != "")
ErrorLog = ErrorLog + System.Environment.NewLine + "Source:" + ClassName + "." + FunctionName;
if (ex != null)
ErrorLog = ErrorLog + System.Environment.NewLine + "Error Message:" + ex.Message + " ,Stack Trace:" + ex.StackTrace.ToString();

file = new System.IO.StreamWriter(ErrorLogPath, true);
file.WriteLine(ErrorLog + System.Environment.NewLine);
//If Backup tacken then set file Created time = Now(Current StartTimeUTC Time)
if (IsBackupTaken)
{
f = new FileInfo(ErrorLogPath);
f.CreationTime = System.DateTime.Now;
}
}
catch (Exception ex1)
{

}
finally
{
if (file != null)
file.Close();
}
}


public static void LogError(Exception ex)
{

StreamWriter file = null;
bool IsBackupTaken = false;
try
{
FileInfo f;
//Checks Backup folder exist if not then creats Folder
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "ErrorBackup"))
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "ErrorBackup");
//Takes Backup if existing file is not of current day.
if (File.Exists(ErrorLogPath))
{
f = new FileInfo(ErrorLogPath);
if (f.CreationTime.DayOfYear != System.DateTime.Now.DayOfYear)
{
File.Move(ErrorLogPath, AppDomain.CurrentDomain.BaseDirectory + "ErrorLog" + System.DateTime.Now.ToString("yyyy-MM-dd_HHmmss") + ".txt");
IsBackupTaken = true;
}
}

//Write Error Log in File
string ErrorLog = "";

if (ex != null)
ErrorLog = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "Error Message:" + ex.Message + " ,Stack Trace:" + ex.StackTrace.ToString();

file = new System.IO.StreamWriter(ErrorLogPath, true);
file.WriteLine(ErrorLog + System.Environment.NewLine);
//If Backup tacken then set file Created time = Now(Current StartTimeUTC Time)
if (IsBackupTaken)
{
f = new FileInfo(ErrorLogPath);
f.CreationTime = System.DateTime.Now;
}

}
catch (Exception ex1)
{
}
finally
{
if (file != null)
file.Close();
}

}

Thanks And Regards.
Kamlesh Nikam
Author: Narayanan             
Posted Date: July 18, 2011     Points: 20   

Hi,
if (Res == System.Windows.Forms.DialogResult.Yes)
{
IsNeedtoMarge = false;
}
else if (Res == System.Windows.Forms.DialogResult.No)
{
IsNeedtoMarge = true;
}
else if (Res == System.Windows.Forms.DialogResult.Cancel)
{
Application.Exit();
}


Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
Author: Ravi Ranjan Kumar             
Posted Date: July 30, 2011     Points: 20   

hey! please be more specific while asking question. your question is still not clear. so please provide some more information regarding to your question.

Thanks & Regards
Ravi Ranjan Kumar
http://raviranjankr.wordpress.com


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend