Exemplo n.º 1
0
 private void LoadCache()
 {
     lock (m_SyncRoot)
     {
         string cacheFile = System.IO.Path.GetFullPath(PositionMemento.DATABASE_PATH + "\\Controls.cache");
         if (File.Exists(cacheFile))
         {
             m_SavedControl.Clear();
             try
             {
                 using (FileStream cachFile = new FileStream(cacheFile, FileMode.Open, FileAccess.Read))
                 {
                     BinaryFormatter frm       = new BinaryFormatter();
                     int             NumEvents = (int)frm.Deserialize(cachFile);
                     for (int i = 0; i < NumEvents; i++)
                     {
                         ControlMemento entry = (ControlMemento)frm.Deserialize(cachFile);
                         m_SavedControl.Add(entry.ControlType, entry);
                     }
                 }
             }
             catch (Exception ex)
             {
                 Trace.WriteLine(ex.GetFullStackTrace());
                 m_CacheReset = true;
             }
         }
         else
         {
             m_CacheReset = true;
         }
     }
 }
Exemplo n.º 2
0
        private static bool LoadDataGridView(ControlMemento memento, DataGridView dgv)
        {
            if (memento.IsNew)
            {
                SaveDataGridView(memento, dgv, null);
                memento.IsNew = false;
            }

            if (memento.Properties.Count == dgv.Columns.Count + 1)
            {
                int idx = 0;
                foreach (DataGridViewColumn column in dgv.Columns)
                {
                    string key = string.Format("Width-{0}", idx);
                    int    val = memento.Properties[key];

                    column.Width = val;
                    idx++;
                }

                return(true);
            }
            else
            {
                //Trace.WriteLineIf(Config.TraceSwitches.UIEvents.TraceVerbose, "FAILED: '" + memento.Properties.Count.ToString() + "' props and '" + dgv.Columns.Count.ToString() + "' columns", "ControlMemento");
                return(false);
            }
        }
Exemplo n.º 3
0
        public static bool LoadControlPosition(Control ctl)
        {
            if (ctl != null)
            {
                ControlMemento memento = m_Cache.GetControlMemento(ctl);

                if (ctl is Form)
                {
                    return(LoadForm(memento, ctl as Form));
                }
                else if (ctl is ListView)
                {
                    return(LoadListView(memento, ctl as ListView));
                }
                else if (ctl is DataGridView)
                {
                    return(LoadDataGridView(memento, ctl as DataGridView));
                }
                else
                {
                    Debug.Assert(false, "Control type not supported.");
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        private static bool LoadListView(ControlMemento memento, ListView lv)
        {
            if (memento.IsNew)
            {
                SaveListView(memento, lv, null);
                memento.IsNew = false;
            }

            if (memento.Properties.Count <= lv.Columns.Count + 1)
            {
                int idx = 0;
                foreach (ColumnHeader col in lv.Columns)
                {
                    string key = string.Format("Width-{0}", idx);

                    if (memento.Properties.ContainsKey(key))
                    {
                        int val = memento.Properties[key];

                        col.Width = val;
                    }
                    else
                    {
                        idx++;
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        public static void SaveControlPosition(Control ctl, object argument)
        {
            if (ctl != null)
            {
                ControlMemento memento = m_Cache.GetControlMemento(ctl);

                if (ctl is Form)
                {
                    SaveForm(memento, ctl as Form);
                }
                else if (ctl is ListView)
                {
                    SaveListView(memento, ctl as ListView, argument);
                }
                else if (ctl is DataGridView)
                {
                    SaveDataGridView(memento, ctl as DataGridView, argument);
                }
                else
                {
                    Debug.Assert(false, "Control type not supported.");
                }

                m_Cache.Save();
            }
        }
Exemplo n.º 6
0
        private static void SaveForm(ControlMemento memento, Form form)
        {
            memento.Properties.Clear();

            memento.Properties.Add("Version", 1);

            memento.Properties.Add("Height", form.Height);
            memento.Properties.Add("Width", form.Width);
            memento.Properties.Add("Top", form.Top);
            memento.Properties.Add("Left", form.Left);
        }
Exemplo n.º 7
0
        public ControlMemento GetControlMemento(Control ctl)
        {
            string key = ctl.GetType().ToString() + "*" + ctl.Name;

            ControlMemento outVal;

            if (m_SavedControl.TryGetValue(key, out outVal))
            {
                return(outVal);
            }
            else
            {
                ControlMemento newMemento = new ControlMemento(key);
                m_SavedControl.Add(key, newMemento);
                return(newMemento);
            }
        }
Exemplo n.º 8
0
        private static void SaveListView(ControlMemento memento, ListView lv, object argument)
        {
            memento.Properties.Clear();

            memento.Properties.Add("Version", 1);

            int idx = 0;

            foreach (ColumnHeader col in lv.Columns)
            {
                string key = string.Format("Width-{0}", idx);
                int    val = col.Width;

                memento.Properties.Add(key, val);
                idx++;
            }
        }
Exemplo n.º 9
0
        private static void SaveDataGridView(ControlMemento memento, DataGridView dgv, object argument)
        {
            memento.Properties.Clear();

            memento.Properties.Add("Version", 1);

            int idx = 0;

            foreach (DataGridViewColumn column in dgv.Columns)
            {
                string key = string.Format("Width-{0}", idx);
                int    val = column.Width;

                memento.Properties.Add(key, val);
                idx++;
            }
        }
Exemplo n.º 10
0
        private static bool LoadForm(ControlMemento memento, Form form)
        {
            if (memento.IsNew)
            {
                memento.Properties["Height"] = form.Height;
                memento.Properties["Width"]  = form.Width;
                memento.Properties["Top"]    = form.Top;
                memento.Properties["Left"]   = form.Left;
                memento.IsNew = false;
            }

            form.Height = memento.Properties["Height"];
            form.Width  = memento.Properties["Width"];
            form.Top    = memento.Properties["Top"];
            form.Left   = memento.Properties["Left"];

            return(true);
        }