110 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			110 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.ComponentModel;
 | 
						|
using System.Data;
 | 
						|
using System.Drawing;
 | 
						|
using System.Text;
 | 
						|
using System.Windows.Forms;
 | 
						|
using System.Reflection;
 | 
						|
 | 
						|
namespace DataLoader
 | 
						|
{
 | 
						|
	public partial class frmPG : Form
 | 
						|
	{
 | 
						|
		private object _SelectedObject;
 | 
						|
		public object SelectedObject
 | 
						|
		{
 | 
						|
			get { return _SelectedObject; }
 | 
						|
			set { _SelectedObject = value; }
 | 
						|
		}
 | 
						|
 | 
						|
		public frmPG(string title, object selectedObject)
 | 
						|
		{
 | 
						|
			InitializeComponent();
 | 
						|
			this.Text = title;
 | 
						|
			_SelectedObject = selectedObject;
 | 
						|
		}
 | 
						|
		private void CheckValidity()
 | 
						|
		{
 | 
						|
			if (SelectedObject.GetType().Name == "DataLoaderSettings")
 | 
						|
			{
 | 
						|
				DataLoaderSettings myDls = (DataLoaderSettings)SelectedObject;
 | 
						|
				string validity = myDls.ValidityCheck;
 | 
						|
				pg.SelectedObject = SelectedObject;
 | 
						|
				tbError.Text = validity;
 | 
						|
				if (validity == "")
 | 
						|
					tbError.Visible = false;
 | 
						|
				else
 | 
						|
				{
 | 
						|
					using (Graphics gr = tbError.CreateGraphics())
 | 
						|
					{
 | 
						|
						SizeF sf = gr.MeasureString(validity, tbError.Font,tbError.ClientRectangle.Width-10);
 | 
						|
						tbError.Height = (int)(tbError.Font.GetHeight(gr.DpiY) + sf.Height);
 | 
						|
					}
 | 
						|
					tbError.Visible = true;
 | 
						|
				}
 | 
						|
			}
 | 
						|
			else
 | 
						|
				tbError.Visible = false;
 | 
						|
			btnOK.Enabled = !tbError.Visible;
 | 
						|
		}
 | 
						|
		private void frmPG_Load(object sender, EventArgs e)
 | 
						|
		{
 | 
						|
			pg.PropertyValueChanged += new PropertyValueChangedEventHandler(pg_PropertyValueChanged);
 | 
						|
			pg.SelectedObject = SelectedObject;
 | 
						|
			Resize += new EventHandler(frmPG_Resize);
 | 
						|
			CheckValidity();
 | 
						|
			MoveSplitterTo(pg, SplitterWidth);
 | 
						|
		}
 | 
						|
		void pg_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
 | 
						|
		{
 | 
						|
			if (e.ChangedItem.Label == "VEProms Exe Folder")
 | 
						|
			{
 | 
						|
				DataLoaderSettings dls = SelectedObject as DataLoaderSettings;
 | 
						|
				if (dls != null)
 | 
						|
					dls.VESamFile = dls.VEPromsPath + "\\vesam.opt";
 | 
						|
			}
 | 
						|
			//if (e.ChangedItem.Label == "Procedure Folder")
 | 
						|
			//{
 | 
						|
			//  DataLoaderSettings dls = SelectedObject as DataLoaderSettings;
 | 
						|
			//  //if (dls != null)
 | 
						|
			//  //  dls.PDFFolder = "";
 | 
						|
			//}
 | 
						|
			CheckValidity();
 | 
						|
		}
 | 
						|
		void frmPG_Resize(object sender, EventArgs e)
 | 
						|
		{
 | 
						|
			MoveSplitterTo(pg, SplitterWidth);
 | 
						|
		}
 | 
						|
		private int _SplitterWidth = 0;
 | 
						|
		public int SplitterWidth
 | 
						|
		{
 | 
						|
			get
 | 
						|
			{
 | 
						|
				if (_SplitterWidth == 0)
 | 
						|
				{
 | 
						|
					using (Graphics gr = this.CreateGraphics())
 | 
						|
						_SplitterWidth = 180 * ((int)gr.DpiX) / 96;
 | 
						|
				}
 | 
						|
				return _SplitterWidth;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		static void MoveSplitterTo(PropertyGrid grid, int x)
 | 
						|
		{
 | 
						|
			// HEALTH WARNING: reflection can be brittle...
 | 
						|
			FieldInfo field = typeof(PropertyGrid)
 | 
						|
					.GetField("gridView",
 | 
						|
							BindingFlags.NonPublic | BindingFlags.Instance);
 | 
						|
			field.FieldType
 | 
						|
					.GetMethod("MoveSplitterTo",
 | 
						|
							BindingFlags.NonPublic | BindingFlags.Instance)
 | 
						|
					.Invoke(field.GetValue(grid), new object[] { x });
 | 
						|
		}
 | 
						|
 | 
						|
		private void btnCancel_Click(object sender, EventArgs e)
 | 
						|
		{
 | 
						|
			PropertyDescriptor pd = pg.SelectedGridItem.PropertyDescriptor;
 | 
						|
			pd.ResetValue(pg.SelectedObject);
 | 
						|
		}
 | 
						|
	}
 | 
						|
} |