Click here to Skip to main content
15,889,116 members
Home / Discussions / C#
   

C#

 
GeneralRe: Removing flash during resize Pin
AndrusM13-Aug-08 23:47
AndrusM13-Aug-08 23:47 
QuestionDevelopment Strategy Pin
BlitzPackage13-Aug-08 6:44
BlitzPackage13-Aug-08 6:44 
AnswerRe: Development Strategy Pin
PIEBALDconsult13-Aug-08 7:57
mvePIEBALDconsult13-Aug-08 7:57 
AnswerRe: Development Strategy Pin
Kevin Marois13-Aug-08 8:02
professionalKevin Marois13-Aug-08 8:02 
AnswerRe: Development Strategy Pin
Manas Bhardwaj13-Aug-08 8:05
professionalManas Bhardwaj13-Aug-08 8:05 
AnswerRe: Development Strategy Pin
BlitzPackage13-Aug-08 8:53
BlitzPackage13-Aug-08 8:53 
GeneralRe: Development Strategy Pin
PIEBALDconsult13-Aug-08 9:37
mvePIEBALDconsult13-Aug-08 9:37 
QuestionHow do I have a class globally accessible throughout an entire project/application Pin
tkrn13-Aug-08 6:21
tkrn13-Aug-08 6:21 
I am trying to create a Log Console that will be a hidden form that will called up when LogConsole.Show() is issued, and write to the Data Grid that is not bound by using the methods as defined. I never done anything like that and I need direction.

Take a look at the code below to get a feel for what i am trying to do.


namespace System.Diagnostics
{
    public class LogConsole
    {
        public static readonly LogConsole Instance = new LogConsole();
        private LogConsoleWrapper LogConsoleForm = new LogConsoleWrapper();

        public void Show()
        {
            LogConsoleForm.Show();
        }

        public void Hide()
        {
            LogConsoleForm.Hide();
        }

        public void Focus()
        {
            LogConsoleForm.Focus();
        }

        public void WriteLine(string message)
        {
            LogConsoleForm.Write(message);
        }

        public void WriteLine(string message, bool error)
        {
            LogConsoleForm.Write(message, error);
        }

        public void WriteLine(string message, Exception ex)
        {
            LogConsoleForm.Write(message, (Exception)ex);
        }
    }

    public class LogConsoleWrapper : System.Windows.Forms.Form
    {
        /// <summary>
		/// Required designer variable.
		/// </summary>
		/// 
		private System.ComponentModel.Container components = null;

        static string sSource = "PIMSLite2008 Log Console";
        static string sLog = "Application";

        public LogConsoleWrapper()
		{
			InitializeComponent();

            if (!EventLog.SourceExists(sSource))
                EventLog.CreateEventSource(sSource, sLog);

            clock.Start();
            lblUser.Text = System.Environment.UserName.ToString().ToUpper();
		}

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// 
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region User Defined Code

        private void clock_Tick(object sender, EventArgs e)
        {
            lblDate.Text = DateTime.Now.ToShortDateString();
            lblTime.Text = DateTime.Now.ToLongTimeString();
        }

        public void Write(string message)
        {
            string[] tmp = new string[3];

            tmp[0] = DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToShortDateString();

            tmp[1] = "N/A";

            tmp[2] = message;

            dgLog.Rows.Add(tmp);
        }

        public void Write(string message, bool error)
        {
            string[] tmp = new string[3];

            tmp[0] = DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToShortDateString();

            if (error == true)
            {
                tmp[1] = "Error";
            }
            else
            {
                tmp[1] = "Information";
            }

            tmp[2] = message;

            dgLog.Rows.Add(tmp);
        }

        public void Write(string message, Exception ex)
        {
            string[] tmp = new string[3];

            tmp[0] = DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToShortDateString();
            tmp[1] = "Error";
            tmp[2] = message;

            dgLog.Rows.Add(tmp);

            string errorMessage = "USER: " + System.Environment.UserName + "\r\n" + new String('-', 100) + "\r\nFUNCTION: " + System.Reflection.MethodBase.GetCurrentMethod().ToString() + "\r\n" + new String('-', 100) + "\r\nSOURCE: \r\n" + ex.Source + "\r\n" + new String('-', 100) + "\r\nMESSAGE: \r\n" + ex.Message + "\r\n" + new String('-', 100) + "\r\nCUSTOM MESSAGE:\r\n" + message + "\r\n" + new String('-', 100) + "\r\nSTACK TRACE: \r\n" + ex.StackTrace;
            EventLog.WriteEntry(sSource, errorMessage, System.Diagnostics.EventLogEntryType.Error);
        }

        #endregion

AnswerRe: How do I have a class globally accessible throughout an entire project/application Pin
BlitzPackage13-Aug-08 6:40
BlitzPackage13-Aug-08 6:40 
AnswerRe: How do I have a class globally accessible throughout an entire project/application Pin
Mark Salsbery13-Aug-08 6:51
Mark Salsbery13-Aug-08 6:51 
GeneralRe: How do I have a class globally accessible throughout an entire project/application Pin
BlitzPackage13-Aug-08 8:30
BlitzPackage13-Aug-08 8:30 
GeneralRe: How do I have a class globally accessible throughout an entire project/application Pin
Mark Salsbery13-Aug-08 8:39
Mark Salsbery13-Aug-08 8:39 
GeneralRe: How do I have a class globally accessible throughout an entire project/application Pin
BlitzPackage13-Aug-08 8:54
BlitzPackage13-Aug-08 8:54 
GeneralRe: How do I have a class globally accessible throughout an entire project/application Pin
Mark Salsbery13-Aug-08 9:05
Mark Salsbery13-Aug-08 9:05 
QuestionWhat is the difference between Excel2003 Addin and Excel2003 Workbook project in c#2008 Pin
Mogaambo13-Aug-08 5:20
Mogaambo13-Aug-08 5:20 
AnswerRe: What is the difference between Excel2003 Addin and Excel2003 Workbook project in c#2008 Pin
Manas Bhardwaj13-Aug-08 5:39
professionalManas Bhardwaj13-Aug-08 5:39 
GeneralRe: What is the difference between Excel2003 Addin and Excel2003 Workbook project in c#2008 Pin
Mogaambo13-Aug-08 6:07
Mogaambo13-Aug-08 6:07 
GeneralRe: What is the difference between Excel2003 Addin and Excel2003 Workbook project in c#2008 Pin
Manas Bhardwaj13-Aug-08 6:09
professionalManas Bhardwaj13-Aug-08 6:09 
GeneralRe: What is the difference between Excel2003 Addin and Excel2003 Workbook project in c#2008 Pin
Mogaambo13-Aug-08 6:21
Mogaambo13-Aug-08 6:21 
QuestionHow to change bgcolor of webbrowser control? Pin
wajans13-Aug-08 5:04
wajans13-Aug-08 5:04 
AnswerRe: How to change bgcolor of webbrowser control? Pin
Manas Bhardwaj13-Aug-08 5:27
professionalManas Bhardwaj13-Aug-08 5:27 
AnswerRe: How to change bgcolor of webbrowser control? Pin
lisan_al_ghaib13-Aug-08 5:38
lisan_al_ghaib13-Aug-08 5:38 
QuestionEncryption methods Pin
Jackeli13-Aug-08 4:39
Jackeli13-Aug-08 4:39 
AnswerRe: Encryption methods Pin
Green Fuze13-Aug-08 5:26
Green Fuze13-Aug-08 5:26 
AnswerRe: Encryption methods Pin
J4amieC13-Aug-08 5:34
J4amieC13-Aug-08 5:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.