How to create many series - c#

Create an object in the class "Series ema = new Series("ema");"
With the button "indicator_Click" download modal dialog.
In the window using the "ComboBox" select options: dig.type, dig.period.
Series ema = new Series("ema");
**********************************************
private void indicator_Click(object sender, EventArgs e)
{
ModalDialogBox dig = new ModalDialogBox();
{
if (dig.ShowDialog() == DialogResult.OK)
{
string formulaName = dig.type;
FinancialFormula formula = (FinancialFormula)Enum.Parse(typeof(FinancialFormula), formulaName, true);
chart1.Series.Add(ema);
chart1.DataManipulator.FinancialFormula(formula, dig.period, "price", "ema");
chart1.Series["ema"].Color = Color.Red;
chart1.Series["ema"].ChartType = SeriesChartType.Line;
chart1.Series["ema"].BorderWidth = 2;
chart1.Series["ema"].ShadowOffset = 1;
}
}
}
Next, if the indicator is not needed, delete it.
private void delete_Click(object sender, EventArgs e)
{
chart1.Series.Remove(ema);
}
I need to be able to add a second, third indicator.
If I try to add a series of the second indicator, an error occurs because the indicator already exists.
You can of course create multiple objects in a class:
Series ema1 = new Series("ema1");
Series ema2 = new Series("ema2");
Series ema3 = new Series("ema3");
but I do not like this method, because I do not know in advance how many indicators will be needed

Related

How do I save multiple user created checkboxes? c# wpf

When I currently save, it saves the checkboxes (but only the color and it's contents, but not if it was checked for some reason), but of course, since I only have 1 setting for each of the properties of the check box (like color, if it is checked(which doesn't work), and it's content), the last checkbox to be added by the user overwrites every other checkbox.
The other problem is that it only creates 1 checkbox, and I don't know how to create the exact number of checkboxes the user has created, with code.
Yesterday I almost spent the whole day looking for solutions, and today I have only spent some hours, maybe two.
Properties.Settings.Default.CheckBoxes is a bool value, to tell it if it's checked or unchecked. Properties.Settings.Default.CheckBoxText
I started to code in c# some days ago, so my code is probably sloppy. Here is my code:
private void DoneBtn_Click(object sender, RoutedEventArgs e)
{
playSimpleSound();
TextRange descText = new TextRange(descTextBox.Document.ContentStart, descTextBox.Document.ContentEnd);
CheckBox c = new CheckBox();
c.Name = "CheckBoxs";
c.IsChecked = false;
c.Content = TitleTextBox.Text + "\n" + descText.Text;
c.Foreground = new SolidColorBrush(Colors.SkyBlue);
checkBoxPanel.Children.Add(c);
checkBoxScroll.Content = checkBoxPanel;
CreateTaskPanel.Visibility = Visibility.Collapsed;
Properties.Settings.Default.CheckBoxText = (string)c.Content;
}
private void MainWindow1_Loaded(object sender, RoutedEventArgs e)
{
if (Properties.Settings.Default.Value == true)
{
CheckBox c = new CheckBox();
c.IsChecked = Properties.Settings.Default.CheckBoxes;
c.Content = Properties.Settings.Default.CheckBoxText;
c.Foreground = Properties.Settings.Default.CheckBoxColor;
checkBoxPanel.Children.Add(c);
}
Properties.Settings.Default.Value = true;
}
private void MainWindow1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Properties.Settings.Default.Save();
}

Generate a New Guid into a Textbox area using a button. (C#)

Looking for help.
I have a form which generates fields into a Class extends groupbox.
I am creating a button to clear and then generate a new GUID into a text box but I can seem to access my textbox which has been creating in the Initialize method.
I created a list to store input.
private List<InputSetItem> _inputSetItems = new List<InputSetItem>();
This is where the textbox is created:
public void initialize()
{
//balanceIdentifier
var balanceIdentifierSet = InputGenerator.GenerateInputControl(this, typeof(Guid), "BalanceIdentifier");
Controls.Add(balanceIdentifierSet.Label);
Controls.Add(balanceIdentifierSet.Input);
balanceIdentifierSet.Label.Left = 820;
balanceIdentifierSet.Input.Left = 1050;
balanceIdentifierSet.Input.Width = 400;
balanceIdentifierSet.Label.Top = 20;
balanceIdentifierSet.Input.Top = 20;
_inputSetItems.Add(balanceIdentifierSet);
// btn_Guid
this.btn_Guid.BackColor = System.Drawing.Color.Blue;
this.btn_Guid.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
this.btn_Guid.ForeColor = System.Drawing.Color.White;
this.btn_Guid.Location = new System.Drawing.Point(1455, 19);
this.btn_Guid.Name = "btn_Guid";
this.btn_Guid.Size = new System.Drawing.Size(75, 26);
this.btn_Guid.TabIndex = 3;
this.btn_Guid.Text = "GENERATE";
this.btn_Guid.UseVisualStyleBackColor = false;
this.btn_Guid.ImageAlign = ContentAlignment.MiddleRight;
this.btn_Guid.TextAlign = ContentAlignment.MiddleLeft;
// Give the button a flat appearance.
this.btn_Guid.FlatStyle = FlatStyle.Flat;
this.Controls.Add(btn_Guid);
this.btn_Guid.Click += new System.EventHandler(this.generateRandomGuid);
}
This is the UI
This is my Generate Method, I cant wrap my head around accesses and updating this textBox
private void generateRandomGuid(object sender, EventArgs e)
{
var delBal = new InputSetItem();
Guid randomGuid = Guid.NewGuid();
//delBal.btn_Guid.Input = randomGuid.ToString();
//delBal.Input.Text;
}
So figured it out.
I had to create a Control instances
private Control _idemp;
Add the textbox assigning it
var IdempotencyRef = InputGenerator.GenerateInputControl(this, typeof(Guid), "IdempotencyReference");
_idemp = IdempotencyRef.Input;
Controls.Add(IdempotencyRef.Label);
Controls.Add(_idemp);
And then updating the method
private void generateRandomGuid(object sender, EventArgs e)
{
Guid randomGuid = Guid.NewGuid();
_idemp.Text = randomGuid.ToString();
}

Opening link using Delegate in C#

I am trying to enable my links to be opened in a web browser.
Everything works fine with the delegate in the for loop but inside the eventGen() method I tried to obtain the name of the link clicked in which one link brings the string nameOfLink as ...
"System.Windows.Forms.LinkLabel, Text: Quora For Programmers"
on using an if statement to verify the selected name and open the link all the if statements are always skipped even if i change the text to
nameOfLink.Equals("Quora For Programmers");
namespace VisitedSites
{
public partial class frmRecentlyVisitedSites : Form
{
// Create an array of Link labels
LinkLabel[] sites = new LinkLabel[3];
// Create links with the tool tips
LinkLabel lnkQuora = new LinkLabel();
ToolTip quora = new ToolTip();
// Create links with the tool tips
LinkLabel lnkIndeed = new LinkLabel();
ToolTip indeed = new ToolTip();
// Create links with the tool tips
LinkLabel lnkHackerRank = new LinkLabel();
ToolTip hackerRank = new ToolTip();
public frmRecentlyVisitedSites()
{
InitializeComponent();
}
private void frmRecentlyVisitedSites_Load(object sender, EventArgs e)
{
// Populate the array with links
sites[0] = lnkQuora;
quora.SetToolTip(lnkQuora, "Quora For Questions!");
sites[1] = lnkIndeed;
indeed.SetToolTip(lnkIndeed, "Qualified For Jobs!");
sites[2] = lnkHackerRank;
hackerRank.SetToolTip(lnkHackerRank, "Comfortable Coding?");
// Configure the LinkLabel's properties.
this.lnkQuora.Location = new System.Drawing.Point(37, 36);
this.lnkQuora.AutoSize = true;
this.lnkQuora.Text = "Quora For Programmers";
// Configure the LinkLabel's properties.
this.lnkIndeed.Location = new System.Drawing.Point(37, 56);
this.lnkIndeed.AutoSize = true;
this.lnkIndeed.Text = "Indeed For The Skilled";
// Configure the LinkLabel's properties.
this.lnkHackerRank.Location = new System.Drawing.Point(37, 76);
this.lnkHackerRank.AutoSize = true;
this.lnkHackerRank.Text = "Hacker Rank For The Robust";
for (int i = 0; i < sites.Length; i++)
{
this.Controls.Add(sites[i]);
sites[i].LinkClicked += new LinkLabelLinkClickedEventHandler(EventGen);
}
}
private void EventGen(object sender, LinkLabelLinkClickedEventArgs e)
{
// Determine the name of the link
string nameOfLink = sender.ToString();
// process the link depending on the name
if(nameOfLink.Equals("System.Windows.Forms.LinkLabel, Text:Quora For Programmers", StringComparison.InvariantCultureIgnoreCase))
{
lnkQuora.LinkVisited = true;
System.Diagnostics.Process.Start("https://www.quora.com/");
}
else if(nameOfLink.Equals("System.Windows.Forms.LinkLabel, Text:Indeed For The Skilled", StringComparison.InvariantCultureIgnoreCase))
{
lnkQuora.LinkVisited = true;
System.Diagnostics.Process.Start("https://www.indeed.com/");
}
else if(nameOfLink.Equals("System.Windows.Forms.LinkLabel, Text:Hacker Rank For The Robust", StringComparison.InvariantCultureIgnoreCase))
{
lnkQuora.LinkVisited = true;
System.Diagnostics.Process.Start("https://www.hackerrank.com/");
}
}
}
}
Just tried your code, you are missing one space
is
System.Windows.Forms.LinkLabel, Text: Quora For Programmers
instead of
System.Windows.Forms.LinkLabel, Text:Quora For Programmers
why not add the links, e.g. "https://www.quora.com/" to the linkdata like link.LinkData = "https://www.quora.com/", and then open that link using Process.Start(e.Link.LinkData as string)?

VSTO Word Content Control - adding multiple RichTextContentControls at run time

I'm creating a Word add-in which allows the user to select various text in a Word document and click a button on the ribbon which will wrap that text with a Content Control (rich text). Eventually these content controls will then be mapped to XML.
The code so far is like this:
public partial class Ribbon1
{
private RichTextContentControl titleRichTextControl;
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void addTitle_Click(object sender, RibbonControlEventArgs e)
{
AddRichTextControlAtSelection();
}
private void AddRichTextControlAtSelection()
{
word.Document currentDocument = Globals.ThisAddIn.Application.ActiveDocument;
currentDocument.ActiveWindow.Selection.Range.Select();
Document extendedDocument = Globals.Factory.GetVstoObject(currentDocument);
titleRichTextControl = extendedDocument.Controls.AddRichTextContentControl("titleRichTextControl");
titleRichTextControl.PlaceholderText = "Enter the title";
titleRichTextControl.Title = "Title";
titleRichTextControl.Tag = "title";
}
}
All this is fine and it works for the first time the button is clicked. However, if there is more than one 'title' (in this case) that needs adding, and the user presses the button a second time, it throws the error:
The control cannot be added because a control with the name titleRichTextControl already exists in the Controls collection.
It's clear why it complains, but i can't think of the correct way to go to allow multiple clicks of the button to generate multiple content controls of the same type (rich text content control) and the same name ("title" for example).
Can anybody point me in the right direction please.
OK this was how i did it in the end:
private void addTitle_Click(object sender, RibbonControlEventArgs e)
{
AddRichTextControlAtSelection();
}
int count = 0;
private void AddRichTextControlAtSelection()
{
word.Document currentDocument = Globals.ThisAddIn.Application.ActiveDocument;
Document extendedDocument = Globals.Factory.GetVstoObject(currentDocument);
if (currentDocument.ContentControls.Count > 0)
{
currentDocument.ActiveWindow.Selection.Range.HighlightColorIndex = word.WdColorIndex.wdYellow;
currentDocument.ActiveWindow.Selection.Range.Select();
richTextControls = new List<RichTextContentControl>();
foreach (word.ContentControl nativeControl in currentDocument.ContentControls)
{
if (nativeControl.Type == Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlRichText)
{
count++;
RichTextContentControl tempControl = extendedDocument.Controls.AddRichTextContentControl("VSTORichTextControl" + count.ToString());
richTextControls.Add(tempControl);
tempControl.Title = "Title";
tempControl.Tag = "title";
break;
}
}
}
else
{
RichTextContentControl VSTORichTextControl;
VSTORichTextControl = extendedDocument.Controls.AddRichTextContentControl("VSTORichTextControl");
VSTORichTextControl.PlaceholderText = "Enter the DM title";
VSTORichTextControl.Title = "Title";
VSTORichTextControl.Tag = "title";
}
}

Combobox closes before i can select a checkbox

I'm currently working in VS 2012.
.NET 4.5 and working on an mmc snap-in. (i know right?!)
so i followed this topic:
Is there a simple way to implement a Checked Combobox in WinForms
as i want something similar to the scheduled task manager.
But that solution does not seem to work for me.
the listview pops up but when i try to click on a checkbox in my listview.
It gives me a big middle finger and closes my dropdown.
is there any way i can suppress the combobox's "focus lost" close event?
i can, not hide the list but then it never hides.
For Example:
// designer class
//
// comboBox1
//
this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.comboBox1.DropDownHeight = 1;
this.comboBox1.DropDownWidth = 1;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.IntegralHeight = false;
this.comboBox1.Location = new System.Drawing.Point(256, 371);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(238, 21);
this.comboBox1.TabIndex = 5;
this.comboBox1.DropDown += new System.EventHandler(this.comboBox1_DropDown);
this.comboBox1.DropDownClosed += new System.EventHandler(this.comboBox1_DropDownClosed);
//
// lstWeekDays
//
this.lstWeekDays.CheckBoxes = true;
this.lstWeekDays.Location = new System.Drawing.Point(50, 63);
this.lstWeekDays.Name = "lstWeekDays";
this.lstWeekDays.Size = new System.Drawing.Size(263, 97);
this.lstWeekDays.TabIndex = 13;
this.lstWeekDays.Tag = "lstlstWeekDays";
this.lstWeekDays.UseCompatibleStateImageBehavior = false;
this.lstWeekDays.View = System.Windows.Forms.View.SmallIcon;
this.lstWeekDays.Visible = false;
// Code behind
public Form1()
{
InitializeComponent();
this.lstWeekDays.Items.Add("Monday");
this.lstWeekDays.Items.Add("Tuesday");
this.lstWeekDays.Items.Add("Wednesday");
this.lstWeekDays.Items.Add("Thursday");
this.lstWeekDays.Items.Add("Friday");
this.lstWeekDays.Items.Add("Saturday");
this.lstWeekDays.Items.Add("Sunday");
}
private void comboBox1_DropDown(object sender, EventArgs e)
{
lstWeekDays.Visible = true;
}
private void comboBox1_DropDownClosed(object sender, EventArgs e)
{
lstWeekDays.Visible = false;
}
Add the checkboxes to this list instead of the panel.

Categories

Resources