473,326 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Run time error

15
hey there, im reasonably new to C# and im currently writing a backup application which im using as a learning resource.

My PC :-
Visual Studio 2005
.NET Framework 2
Component Factory Krypton Tools

Test PC :-
.Net Framework 2

==============================================
The Issue:

On the testing PC, im receiving this error:
==============================================
Expand|Select|Wrap|Line Numbers
  1. System.NullReferenceException: Object reference not set to an instance of an object.
  2.  
  3. ************** Exception Text **************
  4. System.NullReferenceException: Object reference not set to an instance of an object.
  5.    at Backup.frmMain.ShowError(String title, String body)
  6.    at Backup.frmMain.Form1_Load(Object sender, EventArgs e)
  7.    at System.Windows.Forms.Form.OnLoad(EventArgs e)
  8.    at ComponentFactory.Krypton.Toolkit.KryptonForm.OnLoad(EventArgs e)
  9.    at System.Windows.Forms.Form.OnCreateControl()
  10.    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
  11.    at System.Windows.Forms.Control.CreateControl()
  12.    at System.Windows.Forms.Control.WmShowWindow(Message& m)
  13.    at System.Windows.Forms.Control.WndProc(Message& m)
  14.    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
  15.    at System.Windows.Forms.ContainerControl.WndProc(Message& m)
  16.    at System.Windows.Forms.Form.WmShowWindow(Message& m)
  17.    at System.Windows.Forms.Form.WndProc(Message& m)
  18.    at ComponentFactory.Krypton.Toolkit.VisualForm.WndProc(Message& m)
  19.    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  20.    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  21.    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  22.  
  23.  
  24. ************** Loaded Assemblies **************
  25. mscorlib
  26.     Assembly Version: 2.0.0.0
  27.     Win32 Version: 2.0.50727.42 (RTM.050727-4200)
  28.     CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
  29. ----------------------------------------
  30. Backup
  31.     Assembly Version: 1.0.0.0
  32.     Win32 Version: 1.0.0.0
  33.     CodeBase: file:///F:/Backup/Backup.exe
  34. ----------------------------------------
  35. System.Windows.Forms
  36.     Assembly Version: 2.0.0.0
  37.     Win32 Version: 2.0.50727.42 (RTM.050727-4200)
  38.     CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
  39. ----------------------------------------
  40. System
  41.     Assembly Version: 2.0.0.0
  42.     Win32 Version: 2.0.50727.42 (RTM.050727-4200)
  43.     CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
  44. ----------------------------------------
  45. System.Drawing
  46.     Assembly Version: 2.0.0.0
  47.     Win32 Version: 2.0.50727.42 (RTM.050727-4200)
  48.     CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
  49. ----------------------------------------
  50. ComponentFactory.Krypton.Toolkit
  51.     Assembly Version: 3.0.8.0
  52.     Win32 Version: 3.0.8.0
  53.     CodeBase: file:///F:/Backup/ComponentFactory.Krypton.Toolkit.DLL
  54.  
==============================================

Now, I've copied all the Krypton DLL's into the runtime directory of the Backup application. but im not sure what in my code is causing this.

CODE:
==============================================

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.IO;
  9. using System.Threading;
  10. using ComponentFactory.Krypton.Toolkit;
  11.  
  12. namespace Backup
  13. {
  14.  
  15.     public partial class frmMain : ComponentFactory.Krypton.Toolkit.KryptonForm
  16.     {
  17.         public int diff_x;
  18.         public int diff_y;
  19.  
  20.         string USER_NAME = SystemInformation.UserName;
  21.         string DATE = Convert.ToString(System.DateTime.Now.Day + "-" + System.DateTime.Now.Month + "-" + System.DateTime.Now.Year);
  22.  
  23.         string[,] UserDirs;
  24.         enum ext { dir, zip, exe, txt, pfd, xls, ppt, doc };
  25.  
  26.         public frmMain()
  27.         {
  28.             UserDirs = new string[,]
  29.             {
  30.                 {"Favorites", "C:\\Documents and Settings\\" + USER_NAME + "\\Favorites\\"},
  31.                 {"Desktop", "D:\\USERDATA\\" + USER_NAME + "\\Desktop\\"},
  32.                 {"Macros", "C:\\Documents and Settings\\" + USER_NAME + "\\Application Data\\Microsoft\\templates\\"},
  33.                 {"Backups", "H:\\" + USER_NAME + " Backups\\"}
  34.              };
  35.  
  36.             System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;         
  37.             InitializeComponent();
  38.             this.hdrTitleBar.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ButtonDown);
  39.         }
  40.  
  41.         private long FreeHomeDriveSpace()
  42.         {
  43.             return 209715200 - (CalculateSize(new DirectoryInfo("H:\\")));
  44.         }
  45.  
  46.         private bool CopyRecursiveFiles(DirectoryInfo d, string DestinationDirectory, bool CreateEmptyDir,string Extension)
  47.         {
  48.  
  49.             try
  50.             {
  51.                 if (CalculateSize(d) > FreeHomeDriveSpace())
  52.                 {
  53.                     ShowError("Error","You have insufficient space for copying");
  54.                     return false;
  55.                 }
  56.                 else
  57.                 {
  58.                     FileInfo[] fis = d.GetFiles("*." + Extension);
  59.  
  60.                     // Create the destination directory, if CreateEmptyDir or contains files
  61.  
  62.                     if ((fis.Length > 0) || (CreateEmptyDir))
  63.                         Directory.CreateDirectory(DestinationDirectory);
  64.  
  65.                     foreach (FileInfo fi in fis)
  66.                     {
  67.                         if(!File.Exists(DestinationDirectory + "\\" + fi.Name)) fi.CopyTo(DestinationDirectory + "\\" + fi.Name);
  68.                     }
  69.  
  70.                     // Recursive copy children dirs
  71.                     DirectoryInfo[] dis = d.GetDirectories();
  72.  
  73.                     foreach (DirectoryInfo di in dis)
  74.                     {
  75.                         CopyRecursiveFiles(di, DestinationDirectory + "\\" + di.Name, CreateEmptyDir, Extension);
  76.                     }
  77.  
  78.                     Thread t = new Thread(Restore);
  79.                     t.Start();
  80.  
  81.                     Thread h = new Thread(HDrive);
  82.                     h.Start();
  83.                 }
  84.  
  85.  
  86.             }
  87.             catch 
  88.             {
  89.                 return false;
  90.             }
  91.  
  92.             return true;
  93.         }
  94.  
  95.         private bool RestoreRecursiveFiles(DirectoryInfo d, string DestinationDirectory, bool CreateEmptyDir, string Extension)
  96.         {
  97.  
  98.             try
  99.             {
  100.                     FileInfo[] fis = d.GetFiles("*." + Extension);
  101.  
  102.                     // Create the destination directory, if CreateEmptyDir or contains files
  103.  
  104.                     if ((fis.Length > 0) || (CreateEmptyDir))
  105.                         Directory.CreateDirectory(DestinationDirectory);
  106.  
  107.                     foreach (FileInfo fi in fis)
  108.                     {
  109.                         if (!File.Exists(DestinationDirectory + "\\" + fi.Name)) fi.CopyTo(DestinationDirectory + "\\" + fi.Name);
  110.                     }
  111.  
  112.                     // Recursive copy children dirs
  113.                     DirectoryInfo[] dis = d.GetDirectories();
  114.  
  115.                     foreach (DirectoryInfo di in dis)
  116.                     {
  117.                         CopyRecursiveFiles(di, DestinationDirectory + "\\" + di.Name, CreateEmptyDir, Extension);
  118.                     }
  119.  
  120.                     Thread t = new Thread(Restore);
  121.                     t.Start();
  122.  
  123.                     Thread h = new Thread(HDrive);
  124.                     h.Start();
  125.  
  126.             }
  127.             catch (Exception CopyErr)
  128.             {
  129.                 return false;
  130.             }
  131.  
  132.             return true;
  133.         } 
  134.  
  135.         private void BackupDir(DirectoryInfo Dir)
  136.         {
  137.  
  138.             #region # Today Backup Check
  139.                 if (!Directory.Exists(UserDirs[3,1] + DATE))
  140.                 {
  141.                     try
  142.                     {
  143.                         Directory.CreateDirectory("H:\\" + USER_NAME + " Backups\\" + DATE);
  144.                     }
  145.  
  146.                     catch (Exception DateEx)
  147.                     {
  148.                         ShowError("Error", DateEx.ToString());
  149.                     }
  150.                 }
  151.             #endregion
  152.  
  153.         }
  154.  
  155.  
  156.  
  157.         /*----------------------------------------------- 
  158.           * Event : CalculateSize
  159.           * Purpose : Calculates the size of a given directory
  160.           * Args : 
  161.           *          DirectoryInfo (object)
  162.           *          
  163.           * Returns : Long
  164.           * Author : Brendan Scarvell
  165.           * Date : 03/02/08 
  166.           * History : 
  167.           * ----------------------------------------------- 
  168.           * 03/02/08 Created 
  169.           -----------------------------------------------*/
  170.         public long CalculateSize(DirectoryInfo d)
  171.         {
  172.             FileInfo[] files;
  173.             files = d.GetFiles("*");
  174.             long UnFormatedSize = 0L; // need to define this variable
  175.             foreach (FileInfo file in files)
  176.             {
  177.                 UnFormatedSize += file.Length; // no need for any conversions here
  178.             }
  179.             DirectoryInfo[] dirs = d.GetDirectories("*");
  180.             foreach (DirectoryInfo dir in dirs)
  181.             {
  182.                 UnFormatedSize += CalculateSize(dir); // need to add to UnFormatedSize
  183.             }
  184.             return UnFormatedSize;
  185.         } 
  186.  
  187.  
  188.         private void kryptonButton1_Click(object sender, EventArgs e)
  189.         {
  190.             Application.Exit();
  191.         }
  192.  
  193.         /*----------------------------------------------- 
  194.        * Event : GetUnit
  195.        * Purpose : Convert a value into a value
  196.        * Args : 
  197.        *          sender (object)
  198.        *          e (EventArgs)
  199.        * Returns : Null
  200.        * Author : Brendan Scarvell
  201.        * Date : 03/02/08 
  202.        * History : 
  203.        * ----------------------------------------------- 
  204.        * 03/02/08 Created 
  205.        -----------------------------------------------*/
  206.         private void GetUnit(ref string Size)
  207.         {
  208.             string[] units = new string[9] { "Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
  209.             double loop = Convert.ToDouble(Size);
  210.             int UnitPos = 0;
  211.  
  212.             try
  213.             {
  214.                 if (loop >= 1024)
  215.                 {
  216.                     while (loop >= 1)
  217.                     {
  218.                         if ((loop / 1024) >= 1)
  219.                         {
  220.                             loop = loop / 1024;
  221.                             UnitPos++;
  222.                         }
  223.                         else
  224.                         {
  225.                             break;
  226.                         }
  227.                     }
  228.                 }
  229.                 Size = loop.ToString("F1") + " " + units[UnitPos];
  230.             }
  231.  
  232.             catch (Exception cv)
  233.             {
  234.                 MessageBox.Show(cv.ToString());
  235.             }
  236.  
  237.         }
  238.  
  239.         private void Form1_Load(object sender, EventArgs e)
  240.         {
  241.  
  242.  
  243.             #region # StartUp Checks
  244.  
  245.             bool StartThreads = true;
  246.  
  247.             // Check that all directories and paths exist
  248.  
  249.             if (!Directory.Exists("H:\\"))
  250.             {
  251.                 ShowError("Error", "Home Drive doesn't exist. Please contact the InfoService Center to have this resolved");
  252.                 StartThreads = false;
  253.             }
  254.  
  255.             if (!Directory.Exists("H:\\" + USER_NAME))
  256.             {
  257.                 try
  258.                 {
  259.                     Directory.CreateDirectory("H:\\" + USER_NAME);
  260.                 }
  261.  
  262.                 catch (Exception ex)
  263.                 {
  264.                     StartThreads = false;
  265.                     ShowError("Error", ex.ToString());
  266.                 }
  267.             }
  268.  
  269.  
  270.             #endregion
  271.  
  272.  
  273.             if (StartThreads)
  274.             {
  275.                 Thread t = new Thread(HDrive);
  276.                 t.Start();
  277.  
  278.                 Thread r = new Thread(Restore);
  279.                 r.Start();
  280.             }
  281.  
  282.  
  283.             #region # Backup Methods
  284.             /** Load Backup methods **/
  285.  
  286.             ToolStripMenuItem backUpDesktopMenu = new ToolStripMenuItem();
  287.             ToolStripMenuItem backUpFavsMenu = new ToolStripMenuItem();
  288.             ToolStripMenuItem backUpMacrosMenu = new ToolStripMenuItem();
  289.             ToolStripSeparator childSeperator = new ToolStripSeparator();
  290.             ToolStripMenuItem backUpAllMenu = new ToolStripMenuItem();
  291.  
  292.             backUpDesktopMenu.Text = "Desktop";
  293.             backUpDesktopMenu.Image = global::Backup.Properties.Resources.monitor;
  294.             backUpDesktopMenu.Click += new EventHandler(this.BackupDesktop_Click);
  295.  
  296.             backUpFavsMenu.Text = "Favorites";
  297.             backUpFavsMenu.Image = global::Backup.Properties.Resources.world;
  298.             backUpFavsMenu.Click += new EventHandler(this.BackupFavs_Click);
  299.  
  300.             backUpMacrosMenu.Text = "Macros";
  301.             backUpMacrosMenu.Image = global::Backup.Properties.Resources.script_code;
  302.             backUpMacrosMenu.Click += new EventHandler(this.BackupMacros_Click);
  303.  
  304.             backUpAllMenu.Text = "Everything";
  305.             backUpAllMenu.Image = global::Backup.Properties.Resources.tick;
  306.             backUpAllMenu.Click += new EventHandler(this.BackupAll_Click);
  307.  
  308.             cmBackup.Items.AddRange(new ToolStripItem[] { backUpDesktopMenu, backUpFavsMenu, backUpMacrosMenu, childSeperator, backUpAllMenu });
  309.  
  310.             #endregion
  311.  
  312.         }
  313.  
  314.         private void DesktopMenu_Click(object sender, System.EventArgs e)
  315.         {
  316.            ContextMenu x = (ContextMenu) sender;
  317.            bool msgbox;
  318.  
  319.            DialogResult Restore = MessageBox.Show("Are you sure you wish to restore your Desktop Icons from '" + x.Date.ToString() + "'?", "Restore", MessageBoxButtons.YesNo);
  320.  
  321.            if (Restore == DialogResult.Yes)
  322.            {
  323.                msgbox = RestoreRecursiveFiles(new DirectoryInfo(UserDirs[3, 1] + "\\" + x.Date.ToString() + "\\Desktop\\"), UserDirs[1,1],true,"*");
  324.  
  325.                if (msgbox) MessageBox.Show("Desktop Icons successfully restored");
  326.            }
  327.         }
  328.  
  329.         private void AllMenu_Click(object sender, System.EventArgs e)
  330.         {
  331.             ContextMenu x = (ContextMenu)sender;
  332.  
  333.             DialogResult Restore = MessageBox.Show("Are you sure you wish to restore your Desktop Icons from '" + x.Date.ToString() + "'?", "Restore", MessageBoxButtons.YesNo);
  334.  
  335.             if (Restore == DialogResult.Yes)
  336.             {
  337.                 MessageBox.Show("Yes");
  338.             }
  339.             else
  340.             {
  341.                 MessageBox.Show("no...");
  342.             }
  343.  
  344.         }
  345.  
  346.         private void FavsMenu_Click(object sender, System.EventArgs e)
  347.         {
  348.             ContextMenu x = (ContextMenu)sender;
  349.             bool msgbox;
  350.  
  351.             DialogResult Restore = MessageBox.Show("Are you sure you wish to restore your Internet Favorites from '" + x.Date.ToString() + "'?", "Restore", MessageBoxButtons.YesNo);
  352.  
  353.             if (Restore == DialogResult.Yes)
  354.             {
  355.                 msgbox = RestoreRecursiveFiles(new DirectoryInfo(UserDirs[3, 1] + "\\" + x.Date.ToString() + "\\Favorites\\"), UserDirs[0,1],true,"*");
  356.  
  357.                 if (msgbox) MessageBox.Show("Internet Favorites restored successfully");
  358.             }
  359.  
  360.         }
  361.  
  362.         private void MacrosMenu_Click(object sender, System.EventArgs e)
  363.         {
  364.             ContextMenu x = (ContextMenu)sender;
  365.             bool msgbox;
  366.  
  367.             DialogResult Restore = MessageBox.Show("Are you sure you wish to restore your Macros from '" + x.Date.ToString() + "'?", "Restore", MessageBoxButtons.YesNo);
  368.  
  369.             if (Restore == DialogResult.Yes)
  370.             {
  371.                 msgbox = RestoreRecursiveFiles(new DirectoryInfo(UserDirs[3, 1] + "\\" + x.Date.ToString() + "\\Favorites\\"), UserDirs[0, 1], true, "*");
  372.  
  373.                 if (msgbox) MessageBox.Show("Macros restore successfully");
  374.             }
  375.  
  376.         }
  377.  
  378.         /** Restore **/
  379.          private void Restore()
  380.         {
  381.             ContextMenuStrip cmRestore = new ContextMenuStrip();
  382.             cmdRestore.ContextMenuStrip = cmRestore;
  383.  
  384.             DirectoryInfo R = new DirectoryInfo(UserDirs[3,1]);
  385.             int j = 0; // Used to count how many entries there are
  386.  
  387.             try
  388.             {
  389.                 foreach (DirectoryInfo d in R.GetDirectories("*.*"))
  390.                 {
  391.  
  392.                     ToolStripMenuItem parentmnu = new ToolStripMenuItem();
  393.                     ContextMenu childDesktop = new ContextMenu();
  394.                     ContextMenu childFavs = new ContextMenu();
  395.                     ContextMenu childMacros = new ContextMenu();
  396.                     ToolStripSeparator childSeperator = new ToolStripSeparator();
  397.                     ContextMenu childAll = new ContextMenu();
  398.                     bool DisableAll = false; // Set as true if one or more back up methods are missing
  399.  
  400.                     // parent Item
  401.                     parentmnu.Text = d.Name.ToString();
  402.                     parentmnu.Image = global::Backup.Properties.Resources.folder;
  403.  
  404.                     // Child Items
  405.                     childDesktop.Text = "Desktop";
  406.                     childDesktop.Image = global::Backup.Properties.Resources.monitor;
  407.                     childDesktop.Date = parentmnu.Text;
  408.                     childDesktop.Click += new EventHandler(this.DesktopMenu_Click);
  409.                     if (!Directory.Exists(UserDirs[3, 1] + "\\" + parentmnu.Text + "\\Desktop"))
  410.                     {
  411.                         childDesktop.Enabled = false;
  412.                         DisableAll = true;
  413.                     }
  414.  
  415.                     childFavs.Text = "Favorites";
  416.                     childFavs.Date = parentmnu.Text;
  417.                     childFavs.Image = global::Backup.Properties.Resources.world;
  418.                     childFavs.Click += new EventHandler(this.FavsMenu_Click);
  419.                     if (!Directory.Exists(UserDirs[3, 1] + "\\" + parentmnu.Text + "\\Favorites"))
  420.                     {
  421.                         childFavs.Enabled = false;
  422.                         DisableAll = true;
  423.                     }
  424.  
  425.                     childMacros.Text = "Macros";
  426.                     childMacros.Date = parentmnu.Text;
  427.                     childMacros.Image = global::Backup.Properties.Resources.script_code;
  428.                     childMacros.Click += new EventHandler(this.MacrosMenu_Click);
  429.                     if (!Directory.Exists(UserDirs[3, 1] + "\\" + parentmnu.Text + "\\Macros"))
  430.                     {
  431.                         childMacros.Enabled = false;
  432.                         DisableAll = true;
  433.                     }
  434.  
  435.                     childAll.Text = "All";
  436.                     childAll.Image = global::Backup.Properties.Resources.tick;
  437.                     childAll.Click += new EventHandler(this.AllMenu_Click);
  438.                     if (DisableAll) childAll.Enabled = false;
  439.  
  440.  
  441.  
  442.  
  443.                     parentmnu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { childDesktop, childFavs, childMacros, childSeperator, childAll });
  444.                     cmRestore.Items.AddRange(new ToolStripItem[] { parentmnu });
  445.                     j++;
  446.                 }
  447.  
  448.                 if (j == 0)
  449.                 {
  450.                     ToolStripMenuItem parentmnu = new ToolStripMenuItem();
  451.                     parentmnu.Text = "No backups created";
  452.                     parentmnu.Image = global::Backup.Properties.Resources.error;
  453.                     cmRestore.Items.AddRange(new ToolStripItem[] { parentmnu });
  454.                 }
  455.             }
  456.  
  457.             catch (Exception ex)
  458.             {
  459.                 ShowError("FATAL ERROR", ex.Message.ToString());
  460.             }
  461.  
  462.            }
  463.  
  464.          private void bwRestore_DoWork(object sender, DoWorkEventArgs e)
  465.         {
  466.  
  467.         }
  468.  
  469.  
  470.         private void HDrive()
  471.         {
  472.             string HomeDirSpace = CalculateSize(new DirectoryInfo("H:\\")).ToString(); // Store Home drive space into a variable.
  473.  
  474.             GetUnit(ref HomeDirSpace);
  475.             double percentage = (Convert.ToDouble(CalculateSize(new DirectoryInfo("H:\\"))) / 209715200) * 100;
  476.  
  477.             //MessageBox.Show(percentage.ToString());
  478.  
  479.             khpercentage.Values.Description = percentage.ToString("F0") + " %";
  480.             khpercentage.Width = Convert.ToInt32((percentage / 100) * 400);
  481.             lblSpace.Visible = false;
  482.         }
  483.  
  484.         private void bwHdrive_DoWork(object sender, DoWorkEventArgs e)
  485.         {
  486.             string HomeDirSpace = CalculateSize(new DirectoryInfo("H:\\")).ToString(); // Store Home drive space into a variable.
  487.             lbHSpace.Text = "Home Drive Space";
  488.             GetUnit(ref HomeDirSpace);
  489.             double percentage = (Convert.ToDouble(CalculateSize(new DirectoryInfo("H:\\"))) / 209715200) * 100;
  490.  
  491.             khpercentage.Values.Description = percentage.ToString("F0") + " %";
  492.  
  493.             khpercentage.Width = ((int)percentage / 100) * 400;
  494.  
  495.             lblSpace.Visible = false;
  496.         }
  497.  
  498.         private void tmrFlash_Tick(object sender, EventArgs e)
  499.         {
  500.             int count = 0;
  501.  
  502.             if (lblWarning.Visible)
  503.             {
  504.                 lblWarning.Visible = false;
  505.                 count++;
  506.             }
  507.             else if (count == 3)
  508.             {
  509.                 lblWarning.Visible = true;
  510.                 this.Enabled = false;
  511.             }
  512.             else
  513.             {
  514.                 lblWarning.Visible = true;
  515.             }
  516.         }
  517.  
  518.         /*----------------------------------------------- 
  519.        * Event : ButtonDown
  520.        * Purpose : Trigger a mouse move event to move form around
  521.        * Args : 
  522.        *          sender (object)
  523.        *          e (EventArgs)
  524.        * Returns : Null
  525.        * Author : Brendan Scarvell
  526.        * Date : 17 April 2008 
  527.        * History : 
  528.        * ----------------------------------------------- 
  529.        * 17/04/2008 Created 
  530.        -----------------------------------------------*/
  531.         private void ButtonDown(object sender, MouseEventArgs mea)
  532.         {
  533.             diff_x = Form.MousePosition.X - Form.ActiveForm.Location.X;
  534.             diff_y = Form.MousePosition.Y - Form.ActiveForm.Location.Y;
  535.             this.hdrTitleBar.MouseMove += new MouseEventHandler(Form_MouseMove);
  536.         }
  537.  
  538.         /*----------------------------------------------- 
  539.         * Event : ButtonDown
  540.         * Purpose : Trigger a mouse move event to move form around
  541.         * Args : 
  542.         *          sender (object)
  543.         *          e (EventArgs)
  544.         * Returns : Null
  545.         * Author : Brendan Scarvell
  546.         * Date : 17 April 2008 
  547.         * History : 
  548.         * ----------------------------------------------- 
  549.         * 17/04/2008 Created 
  550.         -----------------------------------------------*/
  551.         private void Form_MouseMove(object sender, MouseEventArgs e)
  552.         {
  553.             //as the mouse point moves the form moves with it
  554.             Point p = new Point(MousePosition.X - diff_x, MousePosition.Y - diff_y);
  555.             Form.ActiveForm.Location = p;
  556.             //creates the MouseUp eventhandler
  557.             this.hdrTitleBar.MouseUp += new System.Windows.Forms.MouseEventHandler(Form_MouseUp);
  558.         }
  559.  
  560.         /*----------------------------------------------- 
  561.         * Event : ButtonDown
  562.         * Purpose : Trigger a mouse move event to move form around
  563.         * Args : 
  564.         *          sender (object)
  565.         *          e (EventArgs)
  566.         * Returns : Null
  567.         * Author : Brendan Scarvell
  568.         * Date : 17 April 2008 
  569.         * History : 
  570.         * ----------------------------------------------- 
  571.         * 17/04/2008 Created 
  572.         -----------------------------------------------*/
  573.         private void Form_MouseUp(object sender, MouseEventArgs e)
  574.         {
  575.             //on MouseUp event, remove the MouseMove eventhandler
  576.             this.hdrTitleBar.MouseMove -= new MouseEventHandler(Form_MouseMove);
  577.         }
  578.  
  579.         // Error procedure
  580.  
  581.         private void ShowError(string title, string body)
  582.         {
  583.             // Move the form size to display error box
  584.             frmMain.ActiveForm.Size = new System.Drawing.Size(frmMain.ActiveForm.Size.Width, frmMain.ActiveForm.Size.Height + 80);
  585.             pnlMenu.Location = new System.Drawing.Point(11, (pnlMenu.Location.Y + 80));
  586.             pnlSpace.Location = new System.Drawing.Point(pnlSpace.Location.X, (pnlSpace.Location.Y + 80));
  587.             //pnlFiles.Location = new System.Drawing.Point(pnlFiles.Location.X, (pnlFiles.Location.Y + 80));
  588.             cmdQuit.Location = new System.Drawing.Point(cmdQuit.Location.X, (cmdQuit.Location.Y + 80));
  589.  
  590.             kpError.Visible = true;
  591.             lblWarning.Text = title;
  592.             lblMessage.Text = body;
  593.         }
  594.  
  595.         private void ClearError()
  596.         {
  597.             frmMain.ActiveForm.Size = new System.Drawing.Size(frmMain.ActiveForm.Size.Width, frmMain.ActiveForm.Size.Height - 80);
  598.             pnlMenu.Location = new System.Drawing.Point(11, (pnlMenu.Location.Y - 80));
  599.             pnlSpace.Location = new System.Drawing.Point(pnlSpace.Location.X, (pnlSpace.Location.Y - 80));
  600.             //pnlFiles.Location = new System.Drawing.Point(pnlFiles.Location.X, (pnlFiles.Location.Y - 80));
  601.             cmdQuit.Location = new System.Drawing.Point(cmdQuit.Location.X, (cmdQuit.Location.Y - 80));
  602.  
  603.  
  604.             kpError.Visible = false; ;
  605.             lblWarning.Text = "";
  606.             lblMessage.Text = "";
  607.         }
  608.  
  609.         private void kryptonButton2_Click_1(object sender, EventArgs e)
  610.         {
  611.             ClearError();
  612.         }
  613.  
  614.         private void cmdBackup_Click(object sender, EventArgs e)
  615.         {
  616.             DialogResult a = MessageBox.Show("Are you sure you wish to back your Desktop, Favourites and Macros?", "Back Up", MessageBoxButtons.YesNo);
  617.  
  618.             if (a == DialogResult.Yes)
  619.             {
  620.                 MessageBox.Show("Perform backup");
  621.             }
  622.  
  623.             else
  624.             {
  625.                 MessageBox.Show("Abort");
  626.             }
  627.  
  628.         }
  629.  
  630.         private void asdf_Click(object sender, EventArgs e)
  631.         {
  632.             MessageBox.Show("Testorama");
  633.  
  634.         }
  635.  
  636.         private void cmdRefresh_Click_1(object sender, EventArgs e)
  637.         {
  638.  
  639.             lblSpace.Visible = true;
  640.             Thread t = new Thread(HDrive);
  641.             t.Start();
  642.         }
  643.  
  644.         private void kcmBackup_Opening(object sender, CancelEventArgs e)
  645.         {
  646.  
  647.         }
  648.  
  649.         private void BackupDesktop_Click(object sender, EventArgs e)
  650.         {
  651.             DialogResult dr;
  652.             bool msgbox;
  653.             dr = MessageBox.Show("Are you sure you wish to backup your desktop icons?", "Desktop Backup", MessageBoxButtons.YesNo);
  654.  
  655.             if (dr == DialogResult.Yes)
  656.             {
  657.                 msgbox = CopyRecursiveFiles(new DirectoryInfo(UserDirs[1, 1]), UserDirs[3,1] + DATE + "\\" + UserDirs[1,0], false, "*");
  658.                 if (msgbox) MessageBox.Show("Desktop Backup Completed Successfully");
  659.             }
  660.  
  661.         }
  662.  
  663.         private void BackupFavs_Click(object sender, EventArgs e)
  664.         {
  665.             DialogResult dr;
  666.             bool msgbox;
  667.  
  668.             dr = MessageBox.Show("Are you sure you wish to backup your favorites?", "Desktop Backup", MessageBoxButtons.YesNo);
  669.  
  670.             if (dr == DialogResult.Yes)
  671.             {
  672.                 msgbox = CopyRecursiveFiles(new DirectoryInfo(UserDirs[0, 1]), UserDirs[3, 1] + DATE + "\\" + UserDirs[0, 0], false, "*");
  673.                 if (msgbox) MessageBox.Show("Favorites Backup Completed Successfully");
  674.             }
  675.         }
  676.  
  677.         private void BackupMacros_Click(object sender, EventArgs e)
  678.         {
  679.             DialogResult dr;
  680.             bool msgbox;
  681.  
  682.             dr = MessageBox.Show("Are you sure you wish to backup your macros?", "Desktop Backup", MessageBoxButtons.YesNo);
  683.  
  684.             if (dr == DialogResult.Yes)
  685.             {
  686.                 msgbox = CopyRecursiveFiles(new DirectoryInfo(UserDirs[2, 1]), UserDirs[3, 1] + DATE + "\\" + UserDirs[2, 0], false, "*");
  687.  
  688.                 if (msgbox) MessageBox.Show("Macros Backup Completed Successfully");
  689.             }
  690.  
  691.         }
  692.  
  693.         private void BackupAll_Click(object sender, EventArgs e)
  694.         {
  695.  
  696.             DialogResult dr;
  697.             bool msgbox,msgbox2,msgbox3;
  698.  
  699.             dr = MessageBox.Show("Are you sure you wish to perform a full backup? \n\n WARNING: This could be a time consuming process", "Backup", MessageBoxButtons.YesNo);
  700.  
  701.             if (dr == DialogResult.Yes)
  702.             {
  703.                 msgbox = CopyRecursiveFiles(new DirectoryInfo(UserDirs[0, 1]), UserDirs[3, 1] + DATE + "\\" + UserDirs[0, 0], false, "*");
  704.                 msgbox2 = CopyRecursiveFiles(new DirectoryInfo(UserDirs[1, 1]), UserDirs[3, 1] + DATE + "\\" + UserDirs[1, 0], false, "*");
  705.                 msgbox3 = CopyRecursiveFiles(new DirectoryInfo(UserDirs[2, 1]), UserDirs[3, 1] + DATE + "\\" + UserDirs[2, 0], false, "*");
  706.  
  707.                 if (msgbox && msgbox2 && msgbox3) MessageBox.Show("Backup Completed Successfully");
  708.             }
  709.         }
  710.  
  711.         private void tmrRestore_Tick(object sender, EventArgs e)
  712.         {
  713.             Thread r = new Thread(Restore);
  714.             r.Start();
  715.         }
  716.  
  717.     }
  718.  
  719. }
  720.  
Any help would be greatly,greatly,greatly appreciated
Mar 31 '09 #1
11 5545
Plater
7,872 Expert 4TB
Somewhere you are using an object that has not been defined (it is still null)
Try running in debug to get a better idea of where it is erroring.

since there was no line number listed in the stack trace I am guessing it is happening in the constructor.
Either yours or the ComponentFactory.Krypton.Toolkit.KryptonForm class's constructor.


Although if your timer_tick function executes before this line:
InitializeComponent();
it might cause trouble too
Mar 31 '09 #2
tlhintoq
3,525 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. System.NullReferenceException: Object reference not set to an instance of an object.
  2.    at Backup.frmMain.ShowError(String title, String body)
  3.    at Backup.frmMain.Form1_Load(Object sender, EventArgs e)
  4.    at System.Windows.Forms.Form.OnLoad(EventArgs e)
  5.    at ComponentFactory.Krypton.Toolkit.KryptonForm.OnLoad(EventArgs e)
  6.    at System.Windows.Forms.Form.OnCreateControl()
  7.    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
  8.    at System.Windows.Forms.Control.CreateControl()
  9.  
A tip on reading these. They are in reverse chronological order. Meaning the line at the bottom happened first, the line at the top was most recent and right before the crash.

So you got as far as Backup.frmMain.Form1_Load, then crashed at .ShowError(string title, string body);

I'd start with putting a breakpoint at the first line of your ShowError method and walk through checking to see which variables are null.
Mar 31 '09 #3
tlhintoq
3,525 Expert 2GB
You might also find that a Dictionary<string, string> to be more friendly than a String[ , ]
Mar 31 '09 #4
xenoix
15
Thanks for the help, It definitely is that ShowError procedure, so I have to work out why its doing it (errors on the H drive check). If i log into the network and I have a home drive, (ie: doesnt call the ShowError message), I receive the following.

See Image:
http://img21.imageshack.us/img21/6205/errorg.png

What would be causing that? This is only re-producable on the test box. The Development box doesnt do this, so im assuming something is installed, or something's on here that's not on that.
Mar 31 '09 #5
xenoix
15
Also, not sure if this is any other help:

Filename: ContextMenu.cs
=============================
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.IO;
  9. using System.Threading;
  10. using ComponentFactory.Krypton.Toolkit;
  11.  
  12. namespace Backup
  13. {
  14.     class ContextMenu : ToolStripMenuItem
  15.     {
  16.         public string m_date;
  17.  
  18.          public ContextMenu()
  19.         {
  20.  
  21.         }
  22.  
  23.         public string Date
  24.         {
  25.             get
  26.             {
  27.                 return m_date;
  28.             }
  29.  
  30.             set
  31.             {
  32.                 m_date = value;
  33.             }
  34.         }
  35.  
  36.     }
  37. }
  38.  
  39.  
Mar 31 '09 #6
tlhintoq
3,525 Expert 2GB
@xenoix

Notice how lines 265 and 459 aren't exactly formated the same.
Apr 1 '09 #7
xenoix
15
Thanks alot for that, that has resolved the null problem.

Any tips for that other pesky error? As soon as the application executes, I get that "Backup has encountered a problem and needs to close." I have some feeling that something isnt installed on the other PC because this doesnt happen on my development PC. They both have .NET Framework 2 installed.
Apr 1 '09 #8
tlhintoq
3,525 Expert 2GB
Breakpoints are your friend. Put one early and follow it step-by-step with F-10

Logging... Say it with me... Logging. Have every method write to a text file at the start and end. You can trace how far it got.

Mine tend to start out with environmental information so I can get a feel for the client machine

Expand|Select|Wrap|Line Numbers
  1. 31Mar09    16:11:03.562    #######################################################################
  2. 31Mar09    16:11:03.578    Starting 'MyGreatApplication', version 1.0.0.0 (1.0.0.0)
  3. 31Mar09    16:11:03.578    Saint '1.0.0.5'
  4. 31Mar09    16:11:03.578    System Drive: 'C:'
  5. 31Mar09    16:11:03.578    Logged on as: 'Clint'
  6. 31Mar09    16:11:03.609    Domain      : '''
  7. 31Mar09    16:11:03.718    Workgroup   : 'HomeOffice''
  8. 31Mar09    16:11:03.734    Processor(s):  2 x x86 Family 15 Model 107 Stepping 1, AuthenticAMD
  9. 31Mar09    16:11:03.734    Physical Memory: 3071 MB
  10. 31Mar09    16:11:03.734    Free memory    : 1287 MB
  11. 31Mar09    16:11:03.734    Free VM        : 1829 MB
  12. 31Mar09    16:11:03.828    Op. Sys.    : Microsoft Windows XP Professional (Win32NT)
  13. 31Mar09    16:11:03.828    Op. Sys.    : Microsoft Windows NT 5.1.2600 Service Pack 3'
  14. 31Mar09    16:11:03.828    ===============Network Drives====================
  15. 31Mar09    16:11:03.843    =============== Local Drives=====================
  16. 31Mar09    16:11:03.843    Drive: A:\ (Removable) 
  17. 31Mar09    16:11:04.062    Drive: C:\ (Fixed) 118.74 gig free of 232.88 gig total. SN: 9093FDAE
  18. 31Mar09    16:11:04.093    Drive: D:\ (Fixed) 294.84 gig free of 931.51 gig total. SN: CC199307
  19. 31Mar09    16:11:04.093    Drive: E:\ (Removable) 
  20. 31Mar09    16:11:04.093    Drive: F:\ (Removable) 
  21. 31Mar09    16:11:04.093    Drive: G:\ (Removable) 
  22. 31Mar09    16:11:04.125    Drive: H:\ (Fixed) 229.47 gig free of 298.02 gig total. SN: 3BEC9DA3
  23. 31Mar09    16:11:04.125    Drive: I:\ (CDRom) 
  24. 31Mar09    16:11:04.125    Drive: J:\ (Removable) 
  25. 31Mar09    16:11:04.125    Drive: L:\ (CDRom) 
  26. 31Mar09    16:11:04.140    Drive: P:\ (Fixed) 138.41 gig free of 232.88 gig total. SN: 9093FDAE
  27. 31Mar09    16:11:04.171    Drive: Q:\ (Fixed) 155.30 gig free of 232.88 gig total. SN: 9093FDAE
  28. 31Mar09    16:11:04.187    Drive: R:\ (Fixed) 146.47 gig free of 232.88 gig total. SN: 9093FDAE
  29. 31Mar09    16:11:04.203    Drive: S:\ (Fixed) 127.42 gig free of 232.88 gig total. SN: 9093FDAE
  30. 31Mar09    16:11:04.203    ===============Display adapters===============
  31. 31Mar09    16:11:04.218    0, DISPLAY1, ATI FireMV 2400, 134217733, PCI\VEN_1002&DEV_3151&SUBSYS_31511002&REV_00, \Registry\Machine\System\CurrentControlSet\Control\Video\{E6130F33-B2F7-43F6-9548-7629A84587B2}\0000
  32. 31Mar09    16:11:04.234    1, DISPLAY2, ATI FireMV 2400 Secondary, 134217729, PCI\VEN_1002&DEV_3171&SUBSYS_31501002&REV_00, \Registry\Machine\System\CurrentControlSet\Control\Video\{32124523-E7FE-4C57-A14A-8FF4D0D372A9}\0000
  33. 31Mar09    16:11:04.234    2, DISPLAY3, ATI FireMV 2400, 1, PCI\VEN_1002&DEV_3151&SUBSYS_31511002&REV_00, \Registry\Machine\System\CurrentControlSet\Control\Video\{BED9F312-5DA2-4DA7-AE5C-1459C5170984}\0000
  34. 31Mar09    16:11:04.265    3, DISPLAY4, ATI FireMV 2400 Secondary, 1, PCI\VEN_1002&DEV_3171&SUBSYS_31501002&REV_00, \Registry\Machine\System\CurrentControlSet\Control\Video\{E9C45A42-A6F7-49D2-A2E9-BAD379636B3A}\0000
  35. 31Mar09    16:11:04.359    4, DISPLAYV1, NetMeeting driver, 8, , \Registry\Machine\System\CurrentControlSet\Control\Video\{8B6D7859-A639-4A15-8790-7161976D057A}\0000
  36. 31Mar09    16:11:04.359    5, DISPLAYV2, RDPDD Chained DD, 8, , \Registry\Machine\System\CurrentControlSet\Control\Video\{DEB039CC-B704-4F53-B43E-9DD4432FA2E9}\0000
  37. 31Mar09    16:11:04.359    ===================Displays=====================
  38. 31Mar09    16:11:04.359    Array 0: 'DISPLAY1', {X=0,Y=0,Width=1920,Height=1136}
  39. 31Mar09    16:11:04.359    Array 1: 'DISPLAY2', {X=4170,Y=680,Width=1024,Height=768}
  40. 31Mar09    16:11:04.359    Array 2: 'DISPLAY3', {X=3120,Y=-480,Width=1050,Height=1680}
  41. 31Mar09    16:11:04.359    Array 3: 'DISPLAY4', {X=1920,Y=-720,Width=1200,Height=1920}
  42. 31Mar09    16:11:04.359    ===================Serial Ports=====================
  43. 31Mar09    16:11:04.359    COM3
  44. 31Mar09    16:11:04.359    COM4
  45. 31Mar09    16:11:04.375    #######################################################################
Apr 1 '09 #9
tlhintoq
3,525 Expert 2GB
OH - And I highly recommend putting in some type of Virtual Machine system on your development PC. Its really nice to test on WinXPsp1, WinXPsp2, WinVista... etc. without having to have multiple computers.

Another test for you could be sheer number of files being backed up. Your development machine works fine backing up 50, but what happens for the user when it goes to back up 5,000? Too many threads... in sufficient memory...

Or user rights... Your development machine has god priviledges to the server but your users don't...
Apr 1 '09 #10
xenoix
15
That logging stuff you posted up there, you wouldn't happen to be able to share that at all? =P

(the code for that, that is) I love the Removable drive part.. Something im looking for another application im wanting to write.
Apr 1 '09 #11
tlhintoq
3,525 Expert 2GB
@xenoix
I preach way too much to the effect of:
Can anybody send me code to [...]
The Bytes volunteers are not here to write your code for you.
Bytes is very much a "Give me a fish I eat for a day. Teach me to fish I eat for a lifetime" kind of place. Just giving you the code doesn't help you learn near as effectively as good old-fashioned trial and error.
So I will follow my own advice by pointing you at where to read up.
System.IO.DriveInfo.GetDrives();
Apr 1 '09 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Ken | last post by:
Hi. Can anyone refer me to any articles about the compatibility between c++ polymorphism and real-time programming? I'm currently on a real-time c++ project, and we're having a discussion...
5
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new...
4
by: Christaaay | last post by:
I have been using the code below successfully for almost a year. yesterday, I began getting a run time error 6 (overflow). I am using the code in an Access 2000 database. Can anyone help me...
1
by: MLH | last post by:
I want to change my system time date each time an A97 app is started. Here's how I've been doing it. Am looking for a better way. Sure some of you have researched this. Function...
1
by: Mark | last post by:
I have .aspx code-behinds that inherit from the class below. The code runs just fine, but the form designer bombs at design time when trying to view the .aspx page in VS.NET 2003. If I comment...
1
by: Alfonso Morra | last post by:
Hi I'm compiling some code and need to generate some random numbers. To save time, I decided to use the srand, rand and time functions. My code worked (atleast built fine) until I added time.h,...
4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
9
by: ThunderMusic | last post by:
Hi, I'd like to create a compile time error in my class... maybe there's a way already built in in the framework so I can achieve what I want... I have 2 constructors in my class. One of them...
4
by: ahmurad | last post by:
Dear Xperts, In my database table some fault code type records are inserted and the values are like bellows: Error:2/FC:10; 00:15:13 16/03/2009; Error:2/FC:20; 00:15:15 16/03/2009; ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.