【问题标题】:UserAppDataReigistry not persistingUserAppDataReigistry 不持久
【发布时间】:2016-03-03 10:00:25
【问题描述】:

我有以下课程来保存我的相机设置。

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;

            }

        }
    }
}

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

我在表单的加载和 FormClosed 事件中调用方法

    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);
    }

【问题讨论】:

标签: c# devexpress registry


【解决方案1】:

解决方案是在 AssemblyVersion 中不要有 * 否则每次构建应用程序时,注册表项都会更改。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-11
    • 1970-01-01
    相关资源
    最近更新 更多