propertygrid
とdatetimepicker
を使用して時間(時および分)のみを選択しようとしています。
自分のエディタを作成しました。プロパティグリッドでdatetimepickerを使用して時間を選択
持つコード::あなたのオブジェクトの間の変換System.ComponentModel.TypeConverter
を実装する必要が
public class Tests
{
private DateTimePicker time = new DateTimePicker();
[Editor(typeof(MyEditor), typeof(UITypeEditor))]
public DateTimePicker Time
{
get { return time; }
set { time = value; }
}
public Tests()
{
time.Format = DateTimePickerFormat.Time;
time.CustomFormat = "hh:mm";
time.Value = DateTime.Now;
DateTime t = new DateTime();
}
}
class MyEditor : UITypeEditor
{
IWindowsFormsEditorService editorService;
DateTimePicker picker = new DateTimePicker();
public MyEditor()
{
picker.Format = DateTimePickerFormat.Custom;
picker.CustomFormat = "hh:mm";
picker.ShowUpDown = true;
picker.ValueChanged += new EventHandler(picker_ValueChanged);
}
void picker_ValueChanged(object sender, EventArgs e)
{
this.editorService.CloseDropDown();
}
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (provider != null)
{
this.editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
}
if (this.editorService != null)
{
DateTimePicker tmp = (DateTimePicker)value;
tmp.CustomFormat = "hh:mm";
tmp.Text = tmp.Value.ToString();
picker = tmp;
this.editorService.DropDownControl(picker);
}
return value;
}
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
}
を使用してそれをやりましたもっと簡単に。入力に感謝 – guyl