UserAppDataReigistry不会持续
问题描述:
我有以下类来坚持我的相机设置。UserAppDataReigistry不会持续
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);
}
答
的解决方案是不是有一个*在每一个应用程序生成注册表项将改变时间的AssemblyVersion 否则。
显示所有相关代码。例如。所有你称之为“SaveCameraDevice”和“RestoreCameraDevice”的地方。 –
你是否连载然后回到文件?看到这个链接https://msdn.microsoft.com/en-gb/library/ms973902.aspx –
看着http://geekswithblogs.net/whiletrue/archive/2009/01/11/save-configuration-settings-in -registry.aspx –