UserAppDataReigistry不持久 [英] UserAppDataReigistry not persisting

查看:102
本文介绍了UserAppDataReigistry不持久的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下课程可以保留我的相机设置。

I have the following class to persist my camera settings.

using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors.Camera;        

public class CameraDeviceHelper
    {
        public string DeviceMoniker;
        public string DeviceName;
        public int DeviceResolutionWidth;
        public int DeviceResolutionHeight;

        const string kDeviceName = "CameraDeviceName";
        const string kDeviceMoniker = "CameraDeviceMoniker";
        const string kDeviceResolutionWidth = "CameraDeviceResolutionWidth";
        const string kDeviceResolutionHeight = "CameraDeviceResolutionHeight";

        public bool SaveCameraDevice(CameraControl cc)
        {
            try
            {
                DeviceMoniker = cc.Device.DeviceMoniker;
                DeviceName = cc.Device.Name;
                DeviceResolutionWidth = cc.Device.Resolution.Width;
                DeviceResolutionHeight = cc.Device.Resolution.Height;

                Application.UserAppDataRegistry.SetValue(kDeviceName, DeviceName);
                Application.UserAppDataRegistry.SetValue(kDeviceMoniker, DeviceMoniker);
                Application.UserAppDataRegistry.SetValue(kDeviceResolutionWidth, DeviceResolutionWidth);
                Application.UserAppDataRegistry.SetValue(kDeviceResolutionHeight, DeviceResolutionHeight);

                return true;
            }
            catch (Exception)
            {
                return false;

            }

        }
        public bool RestoreCameraDevice(CameraControl cc)
        {
            try
            {
                DeviceName = Application.UserAppDataRegistry.GetValue(kDeviceName, DeviceName).ToString();
                DeviceMoniker =Application.UserAppDataRegistry.GetValue(kDeviceMoniker, DeviceMoniker).ToString();
                DeviceResolutionWidth = (int) Application.UserAppDataRegistry.GetValue(kDeviceResolutionWidth, DeviceResolutionWidth);
                DeviceResolutionHeight = (int)Application.UserAppDataRegistry.GetValue(kDeviceResolutionHeight, DeviceResolutionHeight);

                var moniker = new DevExpress.Data.Camera.CameraDeviceInfo(DeviceMoniker, DeviceName);
                cc.Device = new CameraDevice(moniker);
                var sz = new Size(DeviceResolutionWidth,DeviceResolutionHeight);
                cc.Device.Resolution = sz;
                if (cc.Device.Resolution.Width != sz.Width)
                { MessageBox.Show("Not set");}

                cc.Start();

                return true;
            }
            catch (Exception)
            {
                return false;

            }

        }
    }
}

在应用程序运行时持久化工作。
但是,当我重新启动应用程序时,设置会丢失。

The persisting works while the application runs. However when I restart the application the settings are lost.

我在窗体的load和FormClosed事件中调用方法

I call the methods in my form's load and FormClosed events

    private void Camera_Load(object sender, EventArgs e)
    {
        textEdit1.Text = PhotoCaption;
        cameraDeviceHelper = new CameraDeviceHelper();
        try
        {
            cameraDeviceHelper.RestoreCameraDevice(cameraControl1);

        }
        catch (Exception)
        {
            // probably first time... so just dont complain
            throw;
        }

    }

    private void Camera_FormClosed(object sender, FormClosedEventArgs e)
    {
        cameraDeviceHelper.SaveCameraDevice(cameraControl1);
    }


推荐答案

AssemblyVersion
中的*,否则每次构建应用程序时,注册表项都会更改。

The solution is not to have an * in the AssemblyVersion otherwise every time the application is built the registry key will change.

这篇关于UserAppDataReigistry不持久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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