BaoKai_202508-Wms-Jingwang..../ShapeControl_CodeProject/FormSaveFileEditor.cs
2025-08-24 09:35:55 +08:00

111 lines
4.0 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms.Design;
using System.Drawing.Drawing2D;
using System.IO;
namespace ShapeControl
{
internal partial class FormSaveFileEditor : Form
{
public string filename = "";
public FormSaveFileEditor()
{
InitializeComponent();
}
private void FormSaveFileEditor_Load(object sender, EventArgs e)
{
this.Hide();
// saveFileDialog1.InitialDirectory = Application.LocalUserAppDataPath;
saveFileDialog1.Filter = "Shape Files|*.shp.jpg";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
filename = saveFileDialog1.FileName;
}
this.Close();
}
}
public class FileSaveEditor : System.Drawing.Design.UITypeEditor
{
public FileSaveEditor()
{
}
// Indicates whether the UITypeEditor provides a form-based (modal) dialog,
// drop down dialog, or no UI outside of the properties window.
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
// Displays the UI for value selection.
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
//if( value.GetType() != typeof(Color))
// return value;
// Uses the IWindowsFormsEditorService to display a
// drop-down UI in the Properties window.
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null)
{
//ColorEditorControl editor = new ColorEditorControl((Color)value);
//edSvc.DropDownControl(editor);
//// Return the value in the appropraite data format.
//if (value.GetType() == typeof(Color))
// return editor.color;
FormSaveFileEditor sfeditor = new FormSaveFileEditor();
edSvc.ShowDialog(sfeditor);
//if (value.GetType() == typeof(Color))
// return sfeditor.color;
return sfeditor.filename;
}
return value;
}
//// Draws a representation of the property's value.
// [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
// public override void PaintValue(System.Drawing.Design.PaintValueEventArgs e)
// {
// // e.Graphics.FillRectangle(new SolidBrush((Color)e.Value), 1, 1, e.Bounds.Width, e.Bounds.Height);
// e.Graphics.FillRectangle(new SolidBrush(Color.Red), 1, 1, e.Bounds.Width, e.Bounds.Height);
// string path =Application.UserAppDataPath +"\\debug.txt";
// //using (StreamWriter sw = File.AppendText(path))
// //{
// // sw.WriteLine("Value:"+ e.Value.ToString() );
// //}
// }
// // Indicates whether the UITypeEditor supports painting a
// // representation of a property's value.
// [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
// public override bool GetPaintValueSupported(System.ComponentModel.ITypeDescriptorContext context)
// {
// return true;
// }
}
}