Page 1 of 1

Adding ContextMenuStrip to TeeChart controls (Series)

Posted: Wed Dec 14, 2005 4:27 pm
by 9638762
I want to open ContextMenuStrip when user right-click CustomPoint(Line,Area,Bar etc..).But
because of Steema's CustomPoint class doesnt inherit from System.Windows.Form.Control class,
it hasn't got ContextMenuStrip Property ...
How could i resolve this problem ?

Posted: Thu Dec 15, 2005 2:54 pm
by narcis
Hi glikoz,

You could use this property from TChart which inherits form System.Windows.Form.Control and use a boolean flag for the cliked series as done here:

Code: Select all

		private void Form1_Load(object sender, System.EventArgs e)
		{
			textBox1.ContextMenu = contextMenu1;
			pictureBox1.ContextMenu = contextMenu1;
			tChart1.ContextMenu=contextMenu1;

			line1.FillSampleValues();
			points1.FillSampleValues();
		}

		private bool flag = false;

		private void series_Click(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if ((sender is Steema.TeeChart.Styles.CustomPoint) && (e.Button==MouseButtons.Right))
			{
				flag = true;
			}
		}

		private void contextMenu1_Popup(object sender, System.EventArgs e)
		{
			// Define the MenuItem objects to display for the TextBox.
			MenuItem menuItem1 = new MenuItem("&Copy");
			MenuItem menuItem2 = new MenuItem("&Find and Replace");
			// Define the MenuItem object to display for the PictureBox.
			MenuItem menuItem3 = new MenuItem("C&hange Picture");
			// Define the MenuItem objects to display for the Chart.
			MenuItem menuItem4 = new MenuItem("&Copy");
			MenuItem menuItem5 = new MenuItem("&Find and Replace");

			// Clear all previously added MenuItems.
			contextMenu1.MenuItems.Clear();
 
			if(contextMenu1.SourceControl == textBox1)
			{
				// Add MenuItems to display for the TextBox.
				contextMenu1.MenuItems.Add(menuItem1);
				contextMenu1.MenuItems.Add(menuItem2);
			}
			else if(contextMenu1.SourceControl == pictureBox1)
			{
				// Add the MenuItem to display for the PictureBox.
				contextMenu1.MenuItems.Add(menuItem3);
			}
			
			else if(contextMenu1.SourceControl == tChart1 && flag)
			{
				// Add the MenuItem to display for the Chart.
				contextMenu1.MenuItems.Add(menuItem4);
				contextMenu1.MenuItems.Add(menuItem5);
				flag = false;
			}
		}