Click here to Skip to main content
15,846,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to save the location of the labels when the user closes, i think i need to make it serialisable or save something to an XML file but cannot figure out how to do it.

the Labels can be moved from one FlowLayoutPanel to another by the use of the if statement and then add/remove methods.

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Xml;
using System.IO;
using System.Xml.Serialization;
using System.Data.SqlClient;





namespace test999
{
    public partial class Form1 : Form

    {


        public Form1()
        {
            InitializeComponent();
        }

        int shrewsbutyTotal;
        int donningtonTotal;
        int margin = 10;
        Point move;




        private void Form1_Load(object sender, EventArgs e)
        {


            labelBackgroundColour();
            flowLayoutPanel1.BorderStyle = BorderStyle.FixedSingle;
            flowLayoutPanel2.BorderStyle = BorderStyle.FixedSingle;
            makeMoveable();
            updateTotals();

            

        }
        void updateTotals()
        {
            shrewsbutyTotal = flowLayoutPanel1.Controls.Count;
            donningtonTotal = flowLayoutPanel2.Controls.Count;
            lbl_total_shrewsbury.Text = "Shrewsbury Vehicle Count: " + shrewsbutyTotal.ToString();
            lbl_total_donnington.Text = "Donnington Vehicle Count: " + donningtonTotal.ToString();
        }



        void labelMouseDown(object sender, MouseEventArgs e)
        {
            Disableflowsnap();
            flowLayoutPanel1.Cursor = Cursors.Hand;
            move = e.Location;

        }
        void labelMouseMove(object sender, MouseEventArgs e)
        {
            Control o = (Control)sender;
            if (e.Button == MouseButtons.Left)
            {
                o.Left += e.X - move.X;
                o.Top += e.Y - move.Y;

            }
        }
        void lableMouseUp(object sender, MouseEventArgs e)
        {

            flowLayoutPanel1.Cursor = Cursors.Default;
            foreach (Label l in flowLayoutPanel1.Controls)
            {
                if ((flowLayoutPanel1.Location.X + l.Right) > flowLayoutPanel1.Right)
                {

                    flowLayoutPanel1.Controls.Remove(l);
                    flowLayoutPanel2.Controls.Add(l);


                    updateTotals();
                }
            }
            foreach (Label l in flowLayoutPanel2.Controls)
            {
                if ((flowLayoutPanel2.Location.X + l.Left < flowLayoutPanel2.Left))
                {
                    flowLayoutPanel2.Controls.Remove(l);
                    flowLayoutPanel1.Controls.Add(l);


                    updateTotals();
                }
            }
            EnableFlowSnap();


        }





        void labelBackgroundColour()
        {

            foreach (Label l in flowLayoutPanel1.Controls)
            {
                l.BackColor = Color.Yellow;

            }
            foreach (Label l in flowLayoutPanel2.Controls)
            {
                l.BackColor = Color.Yellow;

            }
        }
        void makeMoveable()
        {
            foreach (Label l in flowLayoutPanel1.Controls)
            {
                l.MouseDown += new MouseEventHandler(labelMouseDown);
                l.MouseMove += new MouseEventHandler(labelMouseMove);
                l.MouseUp += new MouseEventHandler(lableMouseUp);
            }
            foreach (Label l in flowLayoutPanel2.Controls)
            {
                l.MouseDown += new MouseEventHandler(labelMouseDown);
                l.MouseMove += new MouseEventHandler(labelMouseMove);
                l.MouseUp += new MouseEventHandler(lableMouseUp);
            }
        }
        void Disableflowsnap()
        {
            foreach (FlowLayoutPanel flp in Controls.OfType


What I have tried:

saving to xml, making a serialazable class
Posted
Updated 14-Sep-16 16:11pm

1 solution

I would have looked at using this Easier .NET settings[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900