private void ValidateSize(TextBox source) { try { var tmp = (Point)pointConv.ConvertFromString(source.Text); source.BackColor = Color.White; } catch (Exception) { source.BackColor = Color.Red; } }
internal static Point ReadAttributePoint(XmlNode node, string attributeName) { CheckAttributeExists(node, attributeName); string text = node.Attributes[attributeName].Value; return(PointConverter.ConvertFromString(null, System.Globalization.CultureInfo.CurrentCulture, text)); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object valueObject) { if (!(valueObject is string value)) { throw new InvalidOperationException($"Cannot convert from type {valueObject.GetType()}"); } return(new Wrapper.Point(PointConverter.ConvertFromString(value))); }
// <SnippetPointConverterExample_csharp> private Point pointConverterExample() { PointConverter pConverter = new PointConverter(); Point pointResult = new Point(); string string1 = "10,20"; // pointResult is equal to (10, 20) pointResult = (Point)pConverter.ConvertFromString(string1); return(pointResult); }
public void ReadXml(XmlReader reader) { var pointConverter = new PointConverter(); var sizeConverter = new SizeConverter(); reader.Read(); // To skip the starting 'WindowSettings' element WindowState = (FormWindowState)Enum.Parse(typeof(FormWindowState), reader.ReadElementContentAsString()); Location = (Point)pointConverter.ConvertFromString(reader.ReadElementContentAsString()); Size = (Size)sizeConverter.ConvertFromString(reader.ReadElementContentAsString()); Zoom = reader.ReadElementContentAsInt(); PositionInText = reader.ReadElementContentAsInt(); reader.Read(); // To skip the ending 'WindowSettings' element }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm mainForm = new MainForm(); object location = null; if (args.Length > 0) { if (args[0].StartsWith("prev_instance:")) { // User clicked "New". Get location of previous // instance and open new form slightly lower // and to the right of previous form, unless // previous form's Window State is maximized. Point prevLoc = new Point(); try { PointConverter pc = new PointConverter(); prevLoc = (Point)(pc.ConvertFromString(args[0].Substring(14))); } catch (Exception ex) { MessageBox.Show("Error: " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // if (prevLoc.X > 0) { // Open new form slightly lower and // to the right of previous form. location = new Point(prevLoc.X + 35, prevLoc.Y + 35); mainForm.StartPosition = FormStartPosition.Manual; // mainForm.GetSettings(new Point(prevLoc.X + 35, prevLoc.Y + 35)); } } else { mainForm.GetSettings(null); // Windows Explorer selected this application // to open a file. The first argument should // be the path of the file to open. mainForm.OpenFile(args[0]); } } mainForm.GetSettings(location); Application.Run(mainForm); }
private void CurrentExplorer_Event() { try { if (Properties.Settings.Default.zoomPanes) { if (this.Application.ActiveExplorer().Selection.Count > 0 && this.Application.ActiveExplorer().Selection.Count < 2) { Object selObject = this.Application.ActiveExplorer().Selection[1]; if (selObject is Outlook.MailItem) { Outlook.MailItem mailItem = (selObject as Outlook.MailItem); if (lastItem != mailItem.EntryID) { lastItem = mailItem.EntryID; currentExplorer = this.Application.ActiveExplorer(); int h = currentExplorer.Height; int w = currentExplorer.Width; PointConverter pc = new PointConverter(); Point pt = new Point(); if (isDone) { isDone = false; int sleep = 0; if (Keyboard.IsKeyDown(Keys.Up) || Keyboard.IsKeyDown(Keys.Down)) { sleep = 800; } new Thread(() => { //https://stackoverflow.com/questions/32405387/exiting-c-sharp-function-execution-if-one-of-the-variable-value-during-execution Look at some threading options //Problem when scrolling fast, emails don't zoom. Thread.Sleep(sleep);//Delay so the form can load/set selected item and be active before the scroll attempt... //Thread.CurrentThread.IsBackground = true; pt = (Point)pc.ConvertFromString(w.ToString() + "," + h.ToString()); int posX = Cursor.Position.X; int posY = Cursor.Position.Y; Cursor.Position = pt; keybd_event(VK_TAB, 0x9d, 0, 0); // tab Press keybd_event(VK_CONTROL, 0x9d, 0, 0); // Ctrl Press //Set proper scroll... InspectorWrapperExplained.NativeMethods.MouseInput.ScrollWheel((Properties.Settings.Default.zoomLevel - 100) / 10); //num * 10% IE, 5 = +150% zoom keybd_event(VK_TAB, 0x9d, KEYEVENTF_KEYUP, 0); // Tab Release keybd_event(VK_CONTROL, 0x9d, KEYEVENTF_KEYUP, 0); // Ctrl Release pt = (Point)pc.ConvertFromString(posX.ToString() + "," + posY.ToString()); Cursor.Position = pt; //Return tab to previous location (work around, doesn't work for tabs but does center messages so that uses can scroll through their emails with the arrow keys.). keybd_event(VK_SHIFT, 0x9d, 0, 0); // Shift Press keybd_event(VK_TAB, 0x9d, 0, 0); // tab Press keybd_event(VK_TAB, 0x9d, KEYEVENTF_KEYUP, 0); // Tab Release keybd_event(VK_SHIFT, 0x9d, KEYEVENTF_KEYUP, 0); // Shift Release isDone = true; }).Start(); } } } } } } catch (Exception) { MessageBox.Show("There was an error trying to zoom the preview, if this persists please email our support team."); } }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object valueObject) { return(new PointWpf(PointConverter.ConvertFromString(GetValueAsString(valueObject)))); }
/// <summary> /// Get the presentation objects from file /// </summary> /// <param name="strFilePath">The file path</param> /// <returns>Dictionary of location to object tyoe</returns> public static PresentationDetails ReadPresentation(string strFilePath) { Dictionary <Point, ObjectDetails> dicResult = new Dictionary <Point, ObjectDetails>(); int nLastElementId = 0; PointConverter converter = new PointConverter(); try { // Creating the xml reader XmlReader reader = XmlReader.Create(strFilePath); // As long as not end of file while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == ROOT_ELEMENT) { // Checking that the root element isn't empty element if (!reader.IsEmptyElement) { // Get the element last ID nLastElementId = int.Parse(reader.GetAttribute(LAST_ID_ARRTRIBUTE)); // As long we havn't got yet to the end element while (reader.NodeType != XmlNodeType.EndElement) { reader.Read(); if (reader.Name == OBJECT_ELEMENT) { // Get attributes values Point pCurrent = (Point)converter.ConvertFromString(reader.GetAttribute(POINT_ATTRIBUTE)); PresentationObject currentObject = (PresentationObject)Enum.Parse(typeof(PresentationObject), reader.GetAttribute(TYPE_ATTRIBUTE)); string strName = reader.GetAttribute(NAME_ATTRIBUTE); ObjectDetails details = new ObjectDetails(); details.poType = currentObject; details.strName = strName; // Adding to dictionary dicResult.Add(pCurrent, details); } } } } } } catch (FileNotFoundException ex) { // TODO : write to log throw new Exception("קובץ התצוגה שקיים אינו קיים"); } catch (NotSupportedException ex) { // TODO : write to log throw new Exception("קובץ תצוגה מושחת אנא טען קובץ אחר"); } catch (ArgumentException ex) { // TODO : write to log throw new Exception("קובץ תצוגה מושחת אנא טען קובץ אחר"); } catch (FormatException ex) { // TODO : write to log throw new Exception("קובץ תצוגה מושחת אנא טען קובץ אחר"); } catch (Exception ex) { // TODO : write to log throw new Exception("שגיאה בקריאת נתונים מקובץ אנא נסה שוב"); } return(new PresentationDetails(nLastElementId, dicResult)); }
public static Point ConvertStringToPoint(string point) { PointConverter pointconvert = new PointConverter(); return((Point)pointconvert.ConvertFromString(point)); }
public override object ConvertFromInvariantString(string value) { return(new Wrapper.Point(PointConverter.ConvertFromString(value))); }
public static object GetDPValueFromStr(this DependencyProperty dp, string str) { if (str == null) { return(null); } Type type = dp.PropertyType; if (type.IsEnum) { return(Enum.Parse(type, str)); } if (type == typeof(double)) { return(double.Parse(str)); } if (type == typeof(float)) { return(float.Parse(str)); } if (type == typeof(decimal)) { return(decimal.Parse(str)); } if (type == typeof(string)) { return(str); } if (type == typeof(bool)) { return(bool.Parse(str)); } if (type == typeof(byte)) { return(byte.Parse(str)); } if (type == typeof(int)) { return(int.Parse(str)); } if (type == typeof(char)) { return(char.Parse(str)); } if (type == typeof(Brush)) { if (string.IsNullOrEmpty(str)) { return(null); } Color color = (Color)ColorConverter.ConvertFromString(str); return(new SolidColorBrush(color)); } if (type == typeof(Thickness)) { return(_thicknessConverter.ConvertFromString(str)); } if (type == typeof(FontFamily)) { return(_fontFamilyConverter.ConvertFromString(str)); } if (type == typeof(FontWeight)) { return(_fontWeightConverter.ConvertFromString(str)); } if (type == typeof(Point)) { return(_pointConverter.ConvertFromString(str)); } return(str); }
// This method performs the Point operations public void PerformOperation(object sender, RoutedEventArgs e) { RadioButton li = (sender as RadioButton); // Strings used to display the results String syntaxString, resultType, operationString; // The local variables point1, point2, vector2, etc are defined in each // case block for readability reasons. Each variable is contained within // the scope of each case statement. switch (li.Name) { //begin switch case "rb1": { // Converts a String to a Point using a PointConverter // Returns a Point. PointConverter pConverter = new PointConverter(); Point pointResult = new Point(); string string1 = "10,20"; pointResult = (Point)pConverter.ConvertFromString(string1); // pointResult is equal to (10, 20) // Displaying Results syntaxString = "pointResult = (Point)pConverter1.ConvertFromString(string1);"; resultType = "Point"; operationString = "Converting a String to a Point"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb2": { // Converts a String to a Vector using a VectorConverter // Returns a Vector. VectorConverter vConverter = new VectorConverter(); Vector vectorResult = new Vector(); string string1 = "10,20"; vectorResult = (Vector)vConverter.ConvertFromString(string1); // vectorResult is equal to (10, 20) // Displaying Results syntaxString = "vectorResult = (Vector)vConverter.ConvertFromString(string1);"; resultType = "Vector"; operationString = "Converting a String into a Vector"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb3": { // Converts a String to a Matrix using a MatrixConverter // Returns a Matrix. MatrixConverter mConverter = new MatrixConverter(); Matrix matrixResult = new Matrix(); string string2 = "10,20,30,40,50,60"; matrixResult = (Matrix)mConverter.ConvertFromString(string2); // matrixResult is equal to (10, 20, 30, 40, 50, 60) // Displaying Results syntaxString = "matrixResult = (Vector)mConverter.ConvertFromString(string2);"; resultType = "Matrix"; operationString = "Converting a String into a Matrix"; ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString); break; } case "rb4": { // Converts a String to a Point3D using a Point3DConverter // Returns a Point3D. Point3DConverter p3DConverter = new Point3DConverter(); Point3D point3DResult = new Point3D(); string string3 = "10,20,30"; point3DResult = (Point3D)p3DConverter.ConvertFromString(string3); // point3DResult is equal to (10, 20, 30) // Displaying Results syntaxString = "point3DResult = (Point3D)p3DConverter.ConvertFromString(string3);"; resultType = "Point3D"; operationString = "Converting a String into a Point3D"; ShowResults(point3DResult.ToString(), syntaxString, resultType, operationString); break; } case "rb5": { // Converts a String to a Vector3D using a Vector3DConverter // Returns a Vector3D. Vector3DConverter v3DConverter = new Vector3DConverter(); Vector3D vector3DResult = new Vector3D(); string string3 = "10,20,30"; vector3DResult = (Vector3D)v3DConverter.ConvertFromString(string3); // vector3DResult is equal to (10, 20, 30) // Displaying Results syntaxString = "vector3DResult = (Vector3D)v3DConverter.ConvertFromString(string3);"; resultType = "Vector3D"; operationString = "Converting a String into a Vector3D"; ShowResults(vector3DResult.ToString(), syntaxString, resultType, operationString); break; } case "rb6": { // Converts a String to a Size3D using a Size3DConverter // Returns a Size3D. Size3DConverter s3DConverter = new Size3DConverter(); Size3D size3DResult = new Size3D(); string string3 = "10,20,30"; size3DResult = (Size3D)s3DConverter.ConvertFromString(string3); // size3DResult is equal to (10, 20, 30) // Displaying Results syntaxString = "size3DResult = (Size3D)v3DConverter.ConvertFromString(string3);"; resultType = "Size3D"; operationString = "Converting a String into a Size3D"; ShowResults(size3DResult.ToString(), syntaxString, resultType, operationString); break; } case "rb7": { // Converts a String to a Point4D using a Point4DConverter // Returns a Point4D. Point4DConverter p4DConverter = new Point4DConverter(); Point4D point4DResult = new Point4D(); string string4 = "10,20,30,40"; point4DResult = (Point4D)p4DConverter.ConvertFromString(string4); // point4DResult is equal to (10, 20, 30) // Displaying Results syntaxString = "point4DResult = (Point4D)v3DConverter.ConvertFromString(string3);"; resultType = "Point4D"; operationString = "Converting a String into a Point4D"; ShowResults(point4DResult.ToString(), syntaxString, resultType, operationString); break; } default: break; } //end switch }
public void LoadConfig(bool def = false) { if (def) { tabletOffset = new Point(0, 0); overrideBounds = new Rectangle(0, 0, 0, 0); smoothingStrength = 30; smoothingInterpolation = 4; overlayScreen = 0; tolerance = 300; manualInterpolation = false; stayOnTop = false; disableOverlay = false; allScreens = false; manualOverlayOverride = false; disableCatchUp = false; snapToCursor = false; smoothOnDraw = false; tabletOffsetOverride = false; disableAutoDetection = false; hotkeys[0] = "None"; hotkeys[1] = "None"; hotkeys[2] = "None"; hotkeys[3] = "None"; hotkeys[4] = "None"; hotkeys[5] = "None"; // Main window resetting mainForm.checkBox_smoothOnDraw.Checked = true; mainForm.checkBox_stayOnTop.Checked = true; mainForm.checkBox_tabletMode.Checked = false; mainForm.checkBox_tabletMode.Enabled = false; mainForm.checkBox_manualInterpolation.Checked = false; mainForm.trackBar_smoothingInterpolation.Enabled = false; mainForm.textBox_smoothingInterpolation.Enabled = false; mainForm.textBox_smoothingInterpolation.Text = smoothingInterpolation.ToString(); mainForm.textBox_smoothingStrength.Text = smoothingStrength.ToString(); mainForm.checkBox_smoothOnDraw.Checked = false; mainForm.TopMost = false; // Cursor and overlay resetting overlayForm.cursorColor = Color.FromArgb(128, 128, 128); overlayForm.cursorFillColor = Color.FromArgb(255, 255, 254); overlayForm.cursorType = Overlay.CursorType.Bullseye; overlayForm.Show(); overlayForm.Bounds = Screen.PrimaryScreen.Bounds; mainForm.button_colorDialog.BackColor = overlayForm.cursorColor; // Hotkey resetting for (int i = 0; i < mainForm.hotKeyHandling.Count(); i++) { try { mainForm.hotKeyHandling[i].Dispose(); } catch { // Nothing to dispose! } } } else { try { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // Main window loading smoothingStrength = int.Parse(config.AppSettings.Settings["Strength"].Value); smoothingInterpolation = int.Parse(config.AppSettings.Settings["Interpolation"].Value); manualInterpolation = bool.Parse(config.AppSettings.Settings["Manual Interpolation"].Value); smoothOnDraw = bool.Parse(config.AppSettings.Settings["Smooth On Draw"].Value); stayOnTop = bool.Parse(config.AppSettings.Settings["Stay On Top"].Value); disableAutoDetection = bool.Parse(config.AppSettings.Settings["Disable Auto Detection"].Value); mainForm.tabletMode = bool.Parse(config.AppSettings.Settings["Tablet Mode"].Value); mainForm.checkBox_tabletMode.Enabled = disableAutoDetection; mainForm.checkBox_tabletMode.Checked = mainForm.tabletMode; mainForm.checkBox_smoothOnDraw.Checked = smoothOnDraw; if (manualInterpolation) { mainForm.checkBox_manualInterpolation.Checked = true; mainForm.trackBar_smoothingInterpolation.Enabled = true; mainForm.textBox_smoothingInterpolation.Enabled = true; } mainForm.textBox_smoothingInterpolation.Text = smoothingInterpolation.ToString(); mainForm.textBox_smoothingStrength.Text = smoothingStrength.ToString(); if (stayOnTop) { mainForm.checkBox_stayOnTop.Checked = true; mainForm.TopMost = true; overlayForm.TopMost = true; } // Cursor and overlay loading overlayForm.cursorType = (Overlay.CursorType)Enum.Parse(typeof(Overlay.CursorType), config.AppSettings.Settings["Cursor Graphic"].Value); overlayForm.cursorColor = ColorTranslator.FromHtml(config.AppSettings.Settings["Main Color"].Value); overlayForm.cursorFillColor = ColorTranslator.FromHtml(config.AppSettings.Settings["Fill Color"].Value); overlayScreen = int.Parse(config.AppSettings.Settings["Overlay Screen"].Value); disableOverlay = bool.Parse(config.AppSettings.Settings["Disable Overlay"].Value); allScreens = bool.Parse(config.AppSettings.Settings["All Screens"].Value); manualOverlayOverride = bool.Parse(config.AppSettings.Settings["Manual Overlay Override"].Value); RectangleConverter r = new RectangleConverter(); overrideBounds = (Rectangle)r.ConvertFromString(config.AppSettings.Settings["Override Bounds"].Value); if (disableOverlay) { overlayForm.Hide(); } overlayForm.Bounds = Screen.AllScreens[overlayScreen].Bounds; if (allScreens) { overlayForm.Bounds = new Rectangle(0, 0, SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height); } if (manualOverlayOverride) { overlayForm.Bounds = overrideBounds; } mainForm.button_colorDialog.BackColor = overlayForm.cursorColor; // ...and everything else disableCatchUp = bool.Parse(config.AppSettings.Settings["Disable Catch Up"].Value); snapToCursor = bool.Parse(config.AppSettings.Settings["Snap To Cursor"].Value); tolerance = int.Parse(config.AppSettings.Settings["Tolerance"].Value); tabletOffsetOverride = bool.Parse(config.AppSettings.Settings["Tablet Offset Override"].Value); PointConverter p = new PointConverter(); tabletOffset = (Point)p.ConvertFromString(config.AppSettings.Settings["Tablet Offset"].Value); KeysConverter c = new KeysConverter(); Keys k; Hotkey.KeyModifiers m; hotkeys[0] = config.AppSettings.Settings["Hotkey 1"].Value; if (hotkeys[0] != "None") { k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 1"].Value); m = Hotkey.GetModifiers(k, out k); if (k != Keys.None) { mainForm.RegisterHotkey(mainForm.Handle, 0, m, k); } } hotkeys[1] = config.AppSettings.Settings["Hotkey 2"].Value; if (hotkeys[1] != "None") { k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 2"].Value); m = Hotkey.GetModifiers(k, out k); if (k != Keys.None) { mainForm.RegisterHotkey(mainForm.Handle, 1, m, k); } } hotkeys[2] = config.AppSettings.Settings["Hotkey 3"].Value; if (hotkeys[2] != "None") { k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 3"].Value); m = Hotkey.GetModifiers(k, out k); if (k != Keys.None) { mainForm.RegisterHotkey(mainForm.Handle, 2, m, k); } } hotkeys[3] = config.AppSettings.Settings["Hotkey 4"].Value; if (hotkeys[3] != "None") { k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 4"].Value); m = Hotkey.GetModifiers(k, out k); if (k != Keys.None) { mainForm.RegisterHotkey(mainForm.Handle, 3, m, k); } } hotkeys[4] = config.AppSettings.Settings["Hotkey 5"].Value; if (hotkeys[4] != "None") { k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 5"].Value); m = Hotkey.GetModifiers(k, out k); if (k != Keys.None) { mainForm.RegisterHotkey(mainForm.Handle, 4, m, k); } } hotkeys[5] = config.AppSettings.Settings["Hotkey 6"].Value; if (hotkeys[5] != "None") { k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 6"].Value); m = Hotkey.GetModifiers(k, out k); if (k != Keys.None) { mainForm.RegisterHotkey(mainForm.Handle, 5, m, k); } } } catch { // Quietly fail loading bad configs or no configs } } }