/// <summary>write the code for the designer file where the properties of the control are written</summary> public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl) { // Support NoLabel=true FGenerateLabel = true; if (GenerateLabel(ctrl)) { writer.SetControlProperty(ctrl, "Text", "\"" + ctrl.Label + "\""); ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(ctrl.Label) + 30).ToString()); } else { ctrl.SetAttribute("Width", "15"); } base.SetControlProperties(writer, ctrl); FGenerateLabel = false; if (TYml2Xml.HasAttribute(ctrl.xmlNode, "RadioChecked")) { writer.SetControlProperty(ctrl, "Checked", TYml2Xml.GetAttribute(ctrl.xmlNode, "RadioChecked")); } return(writer.FTemplate); }
/// <summary>write the code for the designer file where the properties of the control are written</summary> public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl) { // TODO this does not work yet. see EventRole Maintain screen if ((!ctrl.HasAttribute("Align")) && (!ctrl.HasAttribute("Width"))) { ctrl.SetAttribute("Stretch", "horizontally"); } base.SetControlProperties(writer, ctrl); TControlDef parentCtrl = writer.FCodeStorage.GetControl(ctrl.parentName); // We need to over-ride any Anchor requests in the YAML to anchor an attached label to anything other than top-left // But pure label controls can be anchored to, say, left-top-right if ((ctrl.controlName.Substring(ctrl.controlTypePrefix.Length) == parentCtrl.controlName.Substring(parentCtrl.controlTypePrefix.Length)) || ((ctrl.HasAttribute("Dock") == false) && (ctrl.HasAttribute("Align") == false))) { // stretch at design time, but do not align to the right writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)))"); } string labelText = ""; if (TYml2Xml.HasAttribute(ctrl.xmlNode, "Text")) { labelText = TYml2Xml.GetAttribute(ctrl.xmlNode, "Text"); } else { labelText = ctrl.Label + ":"; } if (ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", ctrl.GetAttribute("Width")); } else { ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(labelText) + 5).ToString()); } if (ctrl.HasAttribute("Height")) { ctrl.SetAttribute("Height", ctrl.GetAttribute("Height")); } writer.SetControlProperty(ctrl, "Text", "\"" + labelText + "\""); writer.SetControlProperty(ctrl, "Padding", "new System.Windows.Forms.Padding(0, 5, 0, 0)"); if (FRightAlign) { writer.SetControlProperty(ctrl, "TextAlign", "System.Drawing.ContentAlignment.TopRight"); } return(writer.FTemplate); }
/// <summary>write the code for the designer file where the properties of the control are written</summary> public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl) { // TODO this does not work yet. see EventRole Maintain screen if ((!ctrl.HasAttribute("Align")) && (!ctrl.HasAttribute("Width"))) { ctrl.SetAttribute("Stretch", "horizontally"); } base.SetControlProperties(writer, ctrl); // stretch at design time, but do not align to the right writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)))"); string labelText = ""; if (TYml2Xml.HasAttribute(ctrl.xmlNode, "Text")) { labelText = TYml2Xml.GetAttribute(ctrl.xmlNode, "Text"); } else { labelText = ctrl.Label + ":"; } if (ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", ctrl.GetAttribute("Width")); } else { ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(labelText) + 5).ToString()); } if (ctrl.HasAttribute("Height")) { ctrl.SetAttribute("Height", ctrl.GetAttribute("Height")); } writer.SetControlProperty(ctrl, "Text", "\"" + labelText + "\""); writer.SetControlProperty(ctrl, "Padding", "new System.Windows.Forms.Padding(0, 5, 0, 0)"); if (FRightAlign) { writer.SetControlProperty(ctrl, "TextAlign", "System.Drawing.ContentAlignment.TopRight"); } return(writer.FTemplate); }
/// <summary>write the code for the designer file where the properties of the control are written</summary> public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl) { if ((ctrl.HasAttribute("CheckBoxAttachedLabel")) && ((ctrl.GetAttribute("CheckBoxAttachedLabel").ToLower() == "left") || (ctrl.GetAttribute("CheckBoxAttachedLabel").ToLower() == "right"))) { base.FAutoSize = true; if (ctrl.HasAttribute("NoLabel") && (ctrl.GetAttribute("NoLabel").ToLower() == "true")) { writer.SetControlProperty(ctrl, "Text", "\"\""); } else { writer.SetControlProperty(ctrl, "Text", "\"" + ctrl.Label + "\""); if (ctrl.GetAttribute("CheckBoxAttachedLabel").ToLower() == "left") { writer.SetControlProperty(ctrl, "CheckAlign", "System.Drawing.ContentAlignment.MiddleRight"); } else { writer.SetControlProperty(ctrl, "CheckAlign", "System.Drawing.ContentAlignment.MiddleLeft"); } writer.SetControlProperty(ctrl, "Margin", "new System.Windows.Forms.Padding(3, 4, 3, 0)"); ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(ctrl.Label) + 30).ToString()); ctrl.SetAttribute("Height", "17"); } base.SetControlProperties(writer, ctrl); } else { base.FAutoSize = false; ctrl.SetAttribute("Width", 30.ToString ()); base.SetControlProperties(writer, ctrl); writer.SetControlProperty(ctrl, "Text", "\"\""); writer.SetControlProperty(ctrl, "Margin", "new System.Windows.Forms.Padding(3, 0, 3, 0)"); } return(writer.FTemplate); }
/// <summary>write the code for the designer file where the properties of the control are written</summary> public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl) { bool OverrideImageAlign = false; bool OverrideTextAlign = false; bool NoLabel = false; TLogging.LogAtLevel(1, "ButtonGenerator.SetControlProperties for Control " + ctrl.controlName); if (!ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(ctrl.Label) + 15).ToString()); } if (ctrl.HasAttribute("NoLabel") && (ctrl.GetAttribute("NoLabel").ToLower() == "true")) { writer.SetControlProperty(ctrl, "Text", "\"\""); NoLabel = true; } else { writer.SetControlProperty(ctrl, "Size", "new System.Drawing.Size(" + ctrl.GetAttribute("Width").ToString() + ", " + ctrl.GetAttribute("Height").ToString() + ")"); writer.SetControlProperty(ctrl, "Text", "\"" + ctrl.Label + "\""); } if (ctrl.IsOnHorizontalGridButtonPanel) { TLogging.LogAtLevel(1, "Setting Height for Control '" + ctrl.controlName + "' to 23 as it is on a horizontal Grid Button Panel"); FDefaultHeight = 23; if (!ctrl.HasAttribute("ImageAlign")) { if (NoLabel) { //TLogging.LogAtLevel(1, "Setting ImageAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.BottomCenter as it is on a horizontal Grid Button Panel (no Text)"); writer.SetControlProperty(ctrl, "ImageAlign", "System.Drawing.ContentAlignment.BottomCenter"); } else { //TLogging.LogAtLevel(1, "Setting ImageAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.BottomLeft as it is on a horizontal Grid Button Panel"); writer.SetControlProperty(ctrl, "ImageAlign", "System.Drawing.ContentAlignment.BottomLeft"); // Note: In this case want the text centered on the Button, which the TextAlign Property will achieve. // However, its default value is System.Drawing.ContentAlignment.MiddleCenter which means we don't need to explicitly write this out into the Designer file... //TLogging.LogAtLevel(1, "Setting TextAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.MiddleCenter as it is on a horizontal Grid Button Panel"); // writer.SetControlProperty(ctrl, "TextAlign", "System.Drawing.ContentAlignment.MiddleCenter"); } OverrideImageAlign = true; OverrideTextAlign = true; } } else { if (!ctrl.HasAttribute("Height")) { ctrl.SetAttribute("Height", FDefaultHeight.ToString()); } } base.SetControlProperties(writer, ctrl); if (ctrl.GetAttribute("AcceptButton").ToLower() == "true") { writer.Template.AddToCodelet("INITUSERCONTROLS", "this.AcceptButton = " + ctrl.controlName + ";" + Environment.NewLine); } if (ctrl.GetAction() != null) { string img = ctrl.GetAction().actionImage; if (img.Length > 0) { ctrl.SetAttribute("Width", (Convert.ToInt32(ctrl.GetAttribute("Width")) + Convert.ToInt32(ctrl.GetAttribute("IconWidth", "15"))).ToString()); writer.SetControlProperty(ctrl, "Size", "new System.Drawing.Size(" + ctrl.GetAttribute("Width").ToString() + ", " + ctrl.GetAttribute("Height").ToString() + ")"); if (writer.GetControlProperty(ctrl.controlName, "Text") == "\"\"") { if ((!ctrl.HasAttribute("ImageAlign")) && !OverrideImageAlign) { // Note: In this case we want the Image centered on the Button, which the ImageAlign Property will achieve. // However, its default value is System.Drawing.ContentAlignment.MiddleCenter which means we don't need to explicitly write this out into the Designer file... //Console.WriteLine("Setting ImageAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.MiddleCenter as it is NOT on a horizontal Grid Button Panel (no Text)"); // writer.SetControlProperty(ctrl, "ImageAlign", "System.Drawing.ContentAlignment.MiddleCenter"); } } else { if ((!ctrl.HasAttribute("ImageAlign")) && !OverrideImageAlign) { //Console.WriteLine("Setting ImageAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.MiddleLeft as it is NOT on a horizontal Grid Button Panel"); writer.SetControlProperty(ctrl, "ImageAlign", "System.Drawing.ContentAlignment.MiddleLeft"); } } if (!OverrideTextAlign) { //Console.WriteLine("Setting TextAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.MiddleRight as it is NOT on a horizontal Grid Button Panel"); writer.SetControlProperty(ctrl, "TextAlign", "System.Drawing.ContentAlignment.MiddleRight"); } } } return(writer.FTemplate); }