Solved

Remember formsize/position when using multilpe forms.

Posted on 2012-04-11
9
240 Views
Last Modified: 2012-04-11
Dear Experts,

I am programming in C# and I use VS2010.

I hope I explain this right. I am trying to make a Sticky-Form application.
Just what Microsoft Outlook has. By pressing on a button a sticky-form
appears. But when I change the size of the stick-form and then close the
sticky-form and reopen it, the form has then return to its original size and
position.

Is there a code that I can implement that remembers the size of every
resized form and its position.

Peter
0
Comment
Question by:peterkiers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 40
ID: 37831792
You need to record the position ans size before closing the form and set it back to the same position and size when you reopen it.

The best place to record the information is in the application configuration file.

Go to the Project's properties, and in the Settings tab, for each of your forms, create a Size and Location entry. Set it to User level instead of Application. That way it will be read and write, and if many users use the application on the same computer, the data will be recorded separately for each user.

In the FormClosing event to the form, record the settings:

Properties.Settings.Default.Form1_Size = this.Size;
Properties.Settings.Default.Form1_Location = this.Location;
Properties.Settings.Default.Save ( );

Before showing the form later, do the reverse:

Form1.Size=Properties.Settings.Default.Form1_Size;
Form1.Location=Properties.Settings.Default.Form1_Location;
0
 
LVL 1

Author Comment

by:peterkiers
ID: 37831858
What "Type" should I use: int; strings etc...

P.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 37831867
Ohh, system_drawing_size offcaurse...


P
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 1

Author Comment

by:peterkiers
ID: 37831878
I have test the code but it only works for one form and not multiple forms.

Peter
0
 
LVL 1

Author Comment

by:peterkiers
ID: 37831890
In Outlook it works great. How can I do that in my application.

Peter
Naamloos.jpg
0
 
LVL 1

Author Comment

by:peterkiers
ID: 37831907
And this is my code:

        //*------------------------------------------------------------*//
        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.Selected = true;
        }
        //*------------------------------------------------------------*//
        private void lvNotes_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            StickyNotes sticky = new StickyNotes();
            sticky.lblTitle.Text = lvNotes.SelectedItems[0].Text;
            sticky.rtbContent.Text = lvNotes.SelectedItems[0].SubItems[1].Text;
            sticky.lblCreation.Text = lvNotes.SelectedItems[0].SubItems[2].Text;
            sticky.Show();
        }
        //*------------------------------------------------------------*//

Open in new window


p.
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37832484
another option would be to have FormPersistanceHandler class with information to be persisted like formsize, its location , windowstate etc.
You can make it a Datacontract and its members as datamembers.

In each form that you use this FormPersistanceHandler instance type.

On Form Closing : Update The FormPersistanceHandler instance with latest windowstate, location and size information and serialize it to xml file.
On Form Load : Deserialize the XML File to your FormPersistanceHandler instance and update the form properties with FormPersistanceHandler properties.

Hope this provides you with a prototype of how to implement a solution to your problem...
0
 
LVL 1

Author Comment

by:peterkiers
ID: 37832573
Yes, BuggyCoder I think that's the solution too. But I have no idea how to do this.

Peter Kiers
0
 
LVL 40
ID: 37833649
I did not understand that you where always reusing the same class. Since the same form is used for different notes, you would need to have a setting for each sticky note, not for the form. This could not be easily managed.

In Outlook, they do that because when they save the text of the note in the Outlook file, they also save its size and location. You record the text somewhere, isn't it? Then record the Size and Location at the same time. When you reread the text, reread the Size and Location.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question