Can somebody help me to figure out with - how to store correctly Array of Controls added programmatically in my application?
To be more explicitly, I have a function that create programmatically some Labels and PictureBoxes, and added it to Panel Control.
var lbLip = new Label { Text = #"LIP :", Location = new Point(5, 20), Size = new Size(29, 13) };
var lbLipVar = new Label { Text = "", Location = new Point(32, 20), Size = new Size(79, 13) };
var lbRip = new Label { Text = #"RIP :", Location = new Point(5, 40), Size = new Size(31, 13) };
var lbRipVar = new Label { Text = "", Location = new Point(32, 40), Size = new Size(70, 13) };
var imgBox = new PictureBox { Image = Image.FromFile(#"data\icon\red.png"), Location = new Point(100, 40), Size = new Size(16, 11) };
var lbPid = new Label { Text = #"PID :", Location = new Point(5, 60), Size = new Size(31, 13) };
var lbPidVar = new Label { Text = "", Location = new Point(32, 60), Size = new Size(37, 13) };
var lbTime = new Label { Text = #"Time :", Location = new Point(80, 60), Size = new Size(39, 13) };
var lbTimeVar = new Label { Text = "", Location = new Point(115, 60), Size = new Size(49, 13) };
var arrayLb = new Control[9];
arrayLb[0] = lbLip;
arrayLb[1] = lbLipVar;
arrayLb[2] = lbRip;
arrayLb[3] = lbRipVar;
arrayLb[4] = imgBox;
arrayLb[5] = lbPid;
arrayLb[6] = lbPidVar;
arrayLb[7] = lbTime;
arrayLb[8] = lbTimeVar;
plObject.Controls.AddRange(arrayLb);
And now the problem is - how to store this array of Controls for the future updating (editing/removing).
Can somebody suggests a solution how to do this right?
My idea was to create a list of controls
public static List<Control> LiControls = new List<Control>();
and store in it. However I have a lots of Controls to add (~200) - and its hard to handle them all.
I would have create a seperate Serializable class with the properties you need to persist. You can save it to an xml file with the XmlSerializer and if you need to save more properties in the future, just add them to the class and the XmlSerializer will save and load the new properties properly. Good luck !
Related
I made a list with custom numbering but numbering itself gets a different style from paragraphs run. How can I make numbering have the same styles as paragraphs XWPFRun?
This is my numbering
XWPFNumbering numbering = document.CreateNumbering();
var ct_abn = new CT_AbstractNum();
var mlt = new CT_MultiLevelType();
mlt.val = ST_MultiLevelType.multilevel;
ct_abn.multiLevelType = mlt;
ct_abn.lvl = new System.Collections.Generic.List<CT_Lvl> {
new CT_Lvl {
ilvl = "0", start = new CT_DecimalNumber() {val = "1"}, numFmt = new CT_NumFmt() {val = ST_NumberFormat.#decimal},
lvlText = new CT_LevelText() {val = "%1."}, lvlJc = new CT_Jc() {val = ST_Jc.left},
pPr = new CT_PPr {ind = new CT_Ind {left = "360", hanging = 360}, }
},
new CT_Lvl {
ilvl = "1", start = new CT_DecimalNumber() {val = "1"}, numFmt = new CT_NumFmt() {val = ST_NumberFormat.#decimal},
lvlText = new CT_LevelText() {val = "%1.%2."}, lvlJc = new CT_Jc() {val = ST_Jc.left},
pPr = new CT_PPr {ind = new CT_Ind {left = "792", hanging = 792, firstLineSpecified = true}, }
},
new CT_Lvl {
ilvl = "2", start = new CT_DecimalNumber() {val = "1"}, numFmt = new CT_NumFmt() {val = ST_NumberFormat.#decimal},
lvlText = new CT_LevelText() {val = "%1.%2.%3."}, lvlJc = new CT_Jc() {val = ST_Jc.left},
pPr = new CT_PPr {ind = new CT_Ind {left = "792", hanging = 792}}
},
}
This is how it used:
var paragraph = document.CreateParagraph();
paragraph.Alignment = ParagraphAlignment.CENTER;
paragraph.SetNumID(numId, "0"); // applying numbering with lvl = 0
var run = paragraph.CreateRun();
run.SetText("ТЕРМІНИ, ЩО ВЖИВАЮТЬСЯ В ГАРАНТІЙНИХ УМОВАХ");
run.IsBold = true;
run.FontFamily = "Times New Roman";
run.FontSize = 12;
And here's what I get: paragraph itself has correct styles but a number has different
I will appreciate any help
If someone has the same problem, you should add your new style to the document and than use its StyleID to XWPFParagraph like this:
CT_Fonts ctFonts = new CT_Fonts();
ctFonts.ascii = "Times New Roman";
var styles = document.CreateStyles();
styles.AddStyle(
new XWPFStyle(
new CT_Style() {
styleId = "FirstLvlStyle",
rPr = new CT_RPr() {rFonts = ctFonts, b = new CT_OnOff() {val = true}, szCs = new CT_HpsMeasure() {val = 24}}, // gives val / 2 font size
})
);
var paragraph = document.CreateParagraph();
paragraph.Style = "FirstLvlStyle"; // use your StyleId to apply your style
paragraph.SetNumID(numId, "0"); // applying numbering with lvl = 0
UPDATED
Or you can specify style that you want in numbering configuration pPr (Paragraph properties) or rPr (Run properties) like this:
var ct_abn = new CT_AbstractNum();
var mlt = new CT_MultiLevelType();
mlt.val = ST_MultiLevelType.multilevel;
ct_abn.multiLevelType = mlt;
ct_abn.lvl = new System.Collections.Generic.List<CT_Lvl> {
new CT_Lvl {
ilvl = "0", start = new CT_DecimalNumber() {val = "1"}, numFmt = new CT_NumFmt() {val = ST_NumberFormat.#decimal},
lvlText = new CT_LevelText() {val = "%1."}, lvlJc = new CT_Jc() {val = ST_Jc.left},
rPr = new CT_RPr {b = new CT_OnOff {val = true}}, //make text bold
pPr = new CT_PPr {ind = new CT_Ind {left = "360", hanging = 360}}
},
}
I have a Form with one Button. When I click the Button, then programmatically create a Panel with one CheckBox and a TextBox; but for the TextBox the Visible is false.
If I checked the CheckBox, I want to change my TextBox to Visible = true.
Any body can help me?
public void CreateSlide(string name, string title, string desc)
{
var PanelOrder = new Panel()
{
Name = name,
Size = new Size(395, 33),
BorderStyle = BorderStyle.FixedSingle,
Location = new Point(203, 157)
};
var ckOrder = new CheckBox()
{
Name = name,
Text = "Order",
Size = new Size(102, 21),
Location = new Point(3, 5),
FlatStyle = FlatStyle.Flat,
Font = new Font("Segoe UI", 10, FontStyle.Bold)
};
ckOrder.CheckedChanged += new EventHandler(this.ckBoxOrder_CheckedChanged);
var TxtQty = new TextBox
{
Name = name,
Text = "1",
Visible = false,
BorderStyle = BorderStyle.FixedSingle,
Size = new Size(100, 25),
Location = new Point(290, 3)
};
PanelOrder.Controls.Add(ckOrder);
PanelOrder.Controls.Add(TxtQty);
}
Relevant event handler is
private void ckBoxOrder_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked == true)
{
// ??? TxtQty.Visible = true; // <- doesn't compile
}
else
{
// ??? TxtQty.Visible = false; // <- doesn't compile
}
}
You can try using lambda in order to keep all the relevant code within CreateSlide:
public void CreateSlide(string name, string title, string desc) {
var PanelOrder = new Panel() {
Name = name,
Size = new Size(395, 33),
BorderStyle = BorderStyle.FixedSingle,
Location = new Point(203, 157),
Parent = this // <- Put PanelOrder panel on the form
};
var ckOrder = new CheckBox() {
Name = name,
Text = "Order",
Size = new Size(102, 21),
Location = new Point(3, 5),
FlatStyle = FlatStyle.Flat,
Font = new Font("Segoe UI", 10, FontStyle.Bold),
Parent = PanelOrder // <- Put ckOrder on the PanelOrder panel
};
var TxtQty = new TextBox() {
Name = name,
Text = "1",
Visible = false,
BorderStyle = BorderStyle.FixedSingle,
Size = new Size(100, 25),
Location = new Point(290, 3),
Parent = PanelOrder // <- Put TxtQty on the PanelOrder panel
};
// lambda function
ckOrder.CheckedChanged += (s, e) => {
TxtQty.Visible = ckOrder.Checked;
};
}
you need to declare a variable (reference) for the textbox outside the scope of the function that creates it, then you can set it to visible true/false. alternatively (slower) you can enumerate all controls in the form (or the panel), find your text box and set it to visible true/false.
I have seen several questions about doing a custom tooltip for a single line series.
I need a custom tool-tip for each data-point. I would like to add more to the tool-tip than just the dependent value path and the independent value path.
Example I have 2 data points on the same line one with a value(Y-axis)
of 2, date(x-axis) of 4/28/2016, and configuration of A. The other has
a value of 3, date of 4/29/2016, and configuration of B.
How would I also show the configurations? This is all done in code behind because I have a dynamic number of lineseries. So I can't just assign a style to each lineseries in the xaml.
var MyLineSeries = new LineSeries();
lMyLineSeries.DependentValuePath = "Y";
lMyLineSeries.IndependentValuePath = "X";
lMyLineSeries.DataPointStyle = lToolTipDataPointStyle;
This is my code for creating the tool tip style.
var lToolTipDataPointStyle = new Style(typeof(LineDataPoint));
var lTemplate = new ControlTemplate(typeof(LineDataPoint));
var lGridElement = new FrameworkElementFactory(typeof(Border));
//Tooltip
var lStackPanel = new StackPanel();
var lValueContentControl = new ContentControl();
lValueContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.DependentValuePath));
lValueContentControl.ContentStringFormat = "Value: {0}";
var lConfigurationContentControl = new ContentControl();
lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding())//This is what Idk what to bind to???
lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";
lStackPanel.Children.Add(lValueContentControl);
lStackPanel.Children.Add(lConfigurationContentControl);
lGridElement.SetValue(ToolTipService.ToolTipProperty, lStackPanel);
var lEllipseElement = new FrameworkElementFactory(typeof(Ellipse));
lEllipseElement.SetValue(Ellipse.StrokeThicknessProperty, new TemplateBindingExtension(Border.BorderThicknessProperty));
lEllipseElement.SetValue(Ellipse.StrokeProperty, new TemplateBindingExtension(Border.BorderBrushProperty));
lEllipseElement.SetValue(Ellipse.FillProperty, new TemplateBindingExtension(Grid.BackgroundProperty));
lGridElement.AppendChild(lEllipseElement);
lTemplate.VisualTree = lGridElement;
var lTemplateSetter = new Setter();
lTemplateSetter.Property = LineDataPoint.TemplateProperty;
lTemplateSetter.Value = lTemplate;
lToolTipDataPointStyle.Setters.Add(lTemplateSetter);
return lToolTipDataPointStyle;
I figured it out by using the Tag on the Line series.
myLineSeries.Tag = "Configuration";
var lConfigurationContentControl = new ContentControl();
lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.Tag.ToString()))
lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";
We are using open xml for displaying bar graph in exl export but it is not showing labels on data like values above each bar.
Here is the code i am using
BarChart barChart = plotArea.AppendChild<BarChart>(new BarChart(new BarDirection() { Val = new EnumValue<BarDirectionValues>(BarDirectionValues.Column) },
new BarGrouping() { Val = new EnumValue<BarGroupingValues>(BarGroupingValues.Clustered) }));
BarChartSeries barChartSeries = barChart.AppendChild<BarChartSeries>(new BarChartSeries(new Index()
{
Val =
new UInt32Value(i)
},
new Order() { Val = new UInt32Value(i) },
new SeriesText(new NumericValue() { Text = key })));
where key is data value for bar. But still it is not displaying. Can anyone tell where exactly have to put data label so that value labels should be visible on top of each bar in bar graph
You just need to create a DataLabels class, modify how you want them to look and append it to your series. Hope this helps
C.DataLabels dataLabels2 = new C.DataLabels();
C.TextProperties textProperties2 = new C.TextProperties();
A.BodyProperties bodyProperties2 = new A.BodyProperties();
A.ListStyle listStyle2 = new A.ListStyle();
A.Paragraph paragraph2 = new A.Paragraph();
A.ParagraphProperties paragraphProperties2 = new A.ParagraphProperties();
A.DefaultRunProperties defaultRunProperties2 = new A.DefaultRunProperties() { FontSize = 700 };
A.SolidFill solidFill2 = new A.SolidFill();
A.SchemeColor schemeColor2 = new A.SchemeColor() { Val = A.SchemeColorValues.Background1 };
solidFill2.Append(schemeColor2);
defaultRunProperties2.Append(solidFill2);
paragraphProperties2.Append(defaultRunProperties2);
A.EndParagraphRunProperties endParagraphRunProperties2 = new A.EndParagraphRunProperties() { Language = "en-US" };
paragraph2.Append(paragraphProperties2);
paragraph2.Append(endParagraphRunProperties2);
textProperties2.Append(bodyProperties2);
textProperties2.Append(listStyle2);
textProperties2.Append(paragraph2);
C.ShowLegendKey showLegendKey2 = new C.ShowLegendKey() { Val = false };
C.ShowValue showValue2 = new C.ShowValue() { Val = true };
C.ShowCategoryName showCategoryName2 = new C.ShowCategoryName() { Val = false };
C.ShowSeriesName showSeriesName2 = new C.ShowSeriesName() { Val = false };
C.ShowPercent showPercent2 = new C.ShowPercent() { Val = false };
C.ShowBubbleSize showBubbleSize2 = new C.ShowBubbleSize() { Val = false };
C.ShowLeaderLines showLeaderLines2 = new C.ShowLeaderLines() { Val = false };
dataLabels2.Append(textProperties2);
dataLabels2.Append(showLegendKey2);
dataLabels2.Append(showValue2);
dataLabels2.Append(showCategoryName2);
dataLabels2.Append(showSeriesName2);
dataLabels2.Append(showPercent2);
dataLabels2.Append(showBubbleSize2);
dataLabels2.Append(showLeaderLines2);
barChartSeries2.Append(dataLabels2);
I created UITabBarController class to have 5 ViewControllers
controller1 = new Controller1();
controller2 = new Controller2();
controller3 = new Controller3();
controller4 = new Controller4();
controller5 = new Controller5();
controller1.TabBarItem = new UITabBarItem ("first", UIImage.FromFile("/Images/first.png"), 0);
controller5.TabBarItem = new UITabBarItem ("second", UIImage.FromFile("/Images/four.png"), 1);
controller5.TabBarItem = new UITabBarItem ("third", UIImage.FromFile("/Images/four.png"), 2);
controller5.TabBarItem = new UITabBarItem ("four", UIImage.FromFile("/Images/four.png"), 3);
controller5.TabBarItem = new UITabBarItem ("five", UIImage.FromFile("/Images/four.png"), 4);
var tabs = new UIViewController[] {
controller1, controller2, controller3, controller4, controller5
};
ViewControllers = tabs;
In the third controller I have a submit button.
On submit button action, I would like to switch tab from controller3 to controller5.
How would I go about doing this?
Something like this:
this.TabBarController.SelectedIndex = 4;