用户关闭应用程序时保存flowlayoutpanel控件(IE标签) [英] Save a flowlayoutpanel controls (IE labels) when a user closes application

查看:66
本文介绍了用户关闭应用程序时保存flowlayoutpanel控件(IE标签)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在用户关闭时保存标签的位置,我想我需要将其设置为可序列化或将某些内容保存到XML文件中,但无法弄清楚如何执行此操作。



标签可以通过使用if语句从一个FlowLayoutPanel移动到另一个,然后添加/删除方法。



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





我尝试了什么:



保存到xml,制作一个serialazable类



What I have tried:

saving to xml, making a serialazable class

推荐答案

我会看一下使用这个更简单的.NET设置 [ ^ ]
I would have looked at using this Easier .NET settings[^]


这篇关于用户关闭应用程序时保存flowlayoutpanel控件(IE标签)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆