private void pbxCanvas_MouseClick(object sender, MouseEventArgs e) { switch (CurrentMode) { case Mode.mText: libControls.TextField tf = new libControls.TextField(e.X, e.Y, 0, 0); dsControls.Add(tf); tf.OnChanged = OnControlChanged; tf.LauchEditor(pbxCanvas); CurrentMode = Mode.mDrag; break; case Mode.mImage: libControls.ImageField imf = new libControls.ImageField("", e.X, e.Y, 0, 0); dsControls.Add(imf); imf.OnChanged = OnControlChanged; imf.LauchEditor(pbxCanvas); CurrentMode = Mode.mDrag; break; case Mode.mDrag: foreach (libControls.dsControl aControl in dsControls) { if (aControl.Selected) { aControl.Selected = false; } if (aControl.isOver(e.X, e.Y)) { aControl.Selected = true; } } break; } }
private void openXML(String labelPath) { XmlDocument xDoc = new XmlDocument(); xDoc.Load(Path.Combine(labelPath , "label.xml")); XmlNodeList xmlLabel = xDoc.GetElementsByTagName("label"); XmlNodeList listTexts = ((XmlElement)xmlLabel[0]).GetElementsByTagName("text"); XmlNodeList listImages = ((XmlElement)xmlLabel[0]).GetElementsByTagName("image"); foreach (XmlElement nodo in listImages) { int nTop = Int32.Parse(nodo.GetAttribute("top")); int nLeft = Int32.Parse(nodo.GetAttribute("left")); int nHeight = Int32.Parse(nodo.GetAttribute("height")); int nWidth = Int32.Parse(nodo.GetAttribute("width")); string nSrc = nodo.GetAttribute("src"); libControls.ImageField imf = new libControls.ImageField(Path.Combine(Path.Combine(labelPath , "images"), nSrc), nLeft, nTop, nHeight, nWidth); dsControls.Add(imf); imf.OnChanged = OnControlChanged; } foreach (XmlElement nodo in listTexts) { int nTop = Int32.Parse(nodo.GetAttribute("top")); int nLeft = Int32.Parse(nodo.GetAttribute("left")); string nValue = nodo.GetAttribute("value"); libControls.TextField tf = new libControls.TextField(nLeft, nTop, 0, 0); tf.Text = nValue; if (nodo.HasAttribute("format")) { String nFormat = nodo.GetAttribute("format"); TypeConverter tc = TypeDescriptor.GetConverter(typeof(Font)); tf.pFont = (Font)tc.ConvertFromString(nFormat); if (tf.pFont == null) tf.pFont = new Font("Verdana", 10); } else { tf.pFont = new Font("Verdana", 10); } dsControls.Add(tf); tf.OnChanged = OnControlChanged; } XmlNodeList xmlBg = ((XmlElement)xmlLabel[0]).GetElementsByTagName("background"); foreach (XmlElement nodo in xmlBg) { if (nodo.HasAttribute("src")) { try { string nSrc = nodo.GetAttribute("src"); Cover = (Bitmap)Bitmap.FromFile(Path.Combine(Path.Combine(labelPath, "images"), nSrc), false); } catch { Cover = new Bitmap(640, 640); } } else { Cover = new Bitmap(640, 640); } if (nodo.HasAttribute("zoomh")) ZoomH = double.Parse(nodo.GetAttribute("zoomh")); else ZoomH = 1; if (nodo.HasAttribute("zoomv")) ZoomV = double.Parse(nodo.GetAttribute("zoomv")); else ZoomV = 1; if (nodo.HasAttribute("left")) StartX = int.Parse(nodo.GetAttribute("left")); else StartX = 0; if (nodo.HasAttribute("top")) StartY = int.Parse(nodo.GetAttribute("top")); else StartY = 0; } pbxCanvas.Invalidate(); }
private void pbxCanvas_MouseClick(object sender, MouseEventArgs e) { switch (CurrentMode) { case Mode.mText: libControls.TextField tf = new libControls.TextField(e.X,e.Y,0,0); dsControls.Add(tf); tf.OnChanged = OnControlChanged; tf.LaunchEditor(pbxCanvas); CurrentMode = Mode.mDrag; break; case Mode.mImage: libControls.ImageField imf = new libControls.ImageField(String.Empty,e.X,e.Y,0,0); dsControls.Add(imf); imf.OnChanged = OnControlChanged; imf.LaunchEditor(pbxCanvas); CurrentMode = Mode.mDrag; break; case Mode.mDrag: foreach(libControls.dsControl aControl in dsControls) { if (aControl.Selected && controlPressed == false) { aControl.Selected = false; } if (aControl.isOver(e.X,e.Y)) { aControl.Selected = true; } } break; } }