public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { try { string s = (string)value; string[] split = s.Split(",".ToCharArray()); if (split.Length == 3) { CG_Vector3 Trans = new CG_Vector3(TypesHelper.DoubleParse(split[0]), TypesHelper.DoubleParse(split[1]), TypesHelper.DoubleParse(split[2])); return(Trans); } } catch { throw new ArgumentException( "Can not convert '" + (string)value + "' to type CG_Vector3"); } } return(base.ConvertFrom(context, culture, value)); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { try { string s = (string)value; string[] split = s.Split(";".ToCharArray()); if (split.Length == 3) { string[] Scl = split[0].Split(",".ToCharArray()); string[] Pos = split[1].Split(",".ToCharArray()); string[] Rot = split[2].Split(",".ToCharArray()); if (Scl.Length == 3 && Pos.Length == 3 && Rot.Length == 3) { CG_Transform Trans = new CG_Transform(); Trans.Scl.X = TypesHelper.DoubleParse(Scl[0]); Trans.Scl.Y = TypesHelper.DoubleParse(Scl[1]); Trans.Scl.Z = TypesHelper.DoubleParse(Scl[2]); Trans.Pos.X = TypesHelper.DoubleParse(Pos[0]); Trans.Pos.Y = TypesHelper.DoubleParse(Pos[1]); Trans.Pos.Z = TypesHelper.DoubleParse(Pos[2]); Trans.Rot.X = TypesHelper.DoubleParse(Rot[0]); Trans.Rot.Y = TypesHelper.DoubleParse(Rot[1]); Trans.Rot.Z = TypesHelper.DoubleParse(Rot[2]); return(Trans); } } } catch { throw new ArgumentException( "Can not convert '" + (string)value + "' to type SpellingOptions"); } } return(base.ConvertFrom(context, culture, value)); }
public static RichDialogResult ShowInput(InputTypes inType, string Message, string Caption, string defaultValue) { object castedObject = null; DialogResult result = DialogResult.Abort; TextInputForm form = null; while (castedObject == null) { form = new TextInputForm(Message, Caption, ""); form.StartPosition = FormStartPosition.Manual; form.Location = form.PointToClient(Cursor.Position); form.InputValue = defaultValue; form.TopMost = true; result = form.ShowDialog(); if (result != DialogResult.OK) { break; } switch (inType) { case InputTypes.Double: try { double castedDouble = TypesHelper.DoubleParse(form.InputValue); castedObject = castedDouble; } catch (Exception) { TKMessageBox.ShowError("Cannot cast " + form.InputValue + " as a double !!", "Type error"); } break; case InputTypes.Float: try { float castedFloat = TypesHelper.FloatParse(form.InputValue); castedObject = castedFloat; } catch (Exception) { TKMessageBox.ShowError("Cannot cast " + form.InputValue + " as a float !!", "Type error"); } break; case InputTypes.Bool: try { bool castedBool = Convert.ToBoolean(form.InputValue); castedObject = castedBool; } catch (Exception) { TKMessageBox.ShowError("Cannot cast " + form.InputValue + " as a bool !!", "Type error"); } break; case InputTypes.Int: try { int castedInt = Int32.Parse(form.InputValue); castedObject = castedInt; } catch (Exception) { TKMessageBox.ShowError("Cannot cast " + form.InputValue + " as a int !!", "Type error"); } break; default: castedObject = form.InputValue; break; } } return(new RichDialogResult(result, castedObject)); }