Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

Save and load formsize/position when using multiple forms.

Dear Experts,

In my previous question I have asked how to load and save the size and location
of multiple forms into listview columns called lvcSize and lvcLocation.

For the saving-part I have received this solution:

=> myItem.SubItems.Add(sticky.Size.ToString());
=> myItem.SubItems.Add(sticky.Location.ToString());

And I have added these lines above to my code below and
and marked them with //ADD

For the loading-part I received this:

Then to convert those strings back later, use the respective Size.Parse() and Point.Parse() methods:
http://msdn.microsoft.com/en-us/library/system.windows.size.parse(VS.85).aspx
http://msdn.microsoft.com/en-us/library/system.windows.point.parse.aspx

But I don't know how to implement the loading-part solution into my code below.
The only thing I know (I think) is that the methode OpenSticky does the loading of
the StickyNotes-form, so the loading-solution has to be implemented in this methode
Because I have difficulty to understand the code. Can someone help me to implement
the loading-part-solution?

   //*------------------------------------------------------------*//
        private void tbNewNote_ItemClick(object sender, ItemClickEventArgs e)
        {
            StickyNotes sticky = new StickyNotes();
            sticky.lblTitle.Text = "";
            sticky.rtbContent.Clear();
            sticky.lblCreation.Text = (DateTime.Now.ToString());
            sticky.FormClosed += new FormClosedEventHandler(sticky_FormClosed);
            sticky.Show();
        }
        //*------------------------------------------------------------*//
        void sticky_FormClosed(object sender, FormClosedEventArgs e)
        {
            StickyNotes sticky = (StickyNotes)sender;
            ListViewItem myItem = new ListViewItem(sticky.lblTitle.Text, 0);
            myItem = lvNotes.Items.Add(myItem);
            myItem.SubItems.Add(sticky.rtbContent.Text);
            myItem.SubItems.Add(sticky.lblCreation.Text);
            myItem.SubItems.Add(sticky.Size.ToString());       //ADD
            myItem.SubItems.Add(sticky.Location.ToString());     //ADD
            myItem.Selected = true;
        }
        //*------------------------------------------------------------*//
        private void lvNotes_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            OpenSticky(lvNotes.SelectedItems[0]);
        }
        //*------------------------------------------------------------*//
        private void OpenSticky(ListViewItem lvi)
        {
            string Title = lvi.Text;
            string Content = lvi.SubItems[1].Text;
            string Creation = lvi.SubItems[2].Text;
            StickyNotes sticky = null;
            foreach (Form frm in Application.OpenForms)
            {
                if (frm is StickyNotes)
                {
                    sticky = (StickyNotes)frm;
                    if (sticky.lblTitle.Text == Title)
                    {
                        if (sticky.WindowState == FormWindowState.Minimized)
                        {
                            sticky.WindowState = FormWindowState.Normal;
                        }
                        sticky.BringToFront();
                        sticky.Select();
                        return;
                    }
                }
            }
            sticky = new StickyNotes();
            sticky.lblTitle.Text = Title;
            sticky.rtbContent.Text = Content;
            sticky.lblCreation.Text = Creation;
            sticky.Tag = lvi;
            sticky.FormClosed += new FormClosedEventHandler(EditSticky_FormClosed);
            sticky.Show();
        }
        //*------------------------------------------------------------*//
        void EditSticky_FormClosed(object sender, FormClosedEventArgs e)
        {
            StickyNotes sticky = (StickyNotes)sender;
            ListViewItem myItem = (ListViewItem)sticky.Tag;
            myItem.Text = sticky.lblTitle.Text;
            myItem.SubItems[1].Text = sticky.rtbContent.Text;
            myItem.SubItems[2].Text = sticky.lblCreation.Text;
            myItem.SubItems[3].Text = (sticky.Size.ToString());    //ADD
            myItem.SubItems[4].Text = (sticky.Location.ToString());    //ADD
            myItem.Selected = true;
        }

Open in new window



Greetings,

Peter Kiers
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Peter Kiers

ASKER

Thanks Idle_Mind.

500 points are comming to you...

Greetings,

Peter Kiers