0
我有以下類來堅持我的相機設置。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);
}
顯示所有相關代碼。例如。所有你稱之爲「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 –