Advertisement
retesere20

nt-sample--winhost

Feb 20th, 2020
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. #region Using declarations
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.ComponentModel.DataAnnotations;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Xml.Serialization;
  13. using NinjaTrader.Cbi;
  14. using NinjaTrader.Gui;
  15. using NinjaTrader.Gui.Chart;
  16. using NinjaTrader.Gui.SuperDom;
  17. using NinjaTrader.Gui.Tools;
  18. using NinjaTrader.Data;
  19. using NinjaTrader.NinjaScript;
  20. using NinjaTrader.Core.FloatingPoint;
  21. using NinjaTrader.NinjaScript.DrawingTools;
  22. #endregion
  23.  
  24. //This namespace holds Indicators in this folder and is required. Do not change it.
  25. namespace NinjaTrader.NinjaScript.Indicators.customs
  26. {
  27. public class a1: Indicator
  28. {
  29. protected override void OnStateChange()
  30. {
  31. if (State == State.SetDefaults)
  32. {
  33. Description = @"Enter the description for your new custom Indicator here.";
  34. Name = "a1";
  35. Calculate = Calculate.OnEachTick;
  36. IsOverlay = false;
  37. DisplayInDataBox = true;
  38. DrawOnPricePanel = true;
  39. DrawHorizontalGridLines = true;
  40. DrawVerticalGridLines = true;
  41. PaintPriceMarkers = true;
  42. ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
  43. //Disable this property if your indicator requires custom values that cumulate with each new market data event.
  44. //See Help Guide for additional information.
  45. IsSuspendedWhileInactive = true;
  46. //
  47. AddPlot(Brushes.Orange, "a1");
  48. }
  49. else if (State == State.Configure)
  50. {
  51. }
  52. else if (State == State.DataLoaded)
  53. {
  54. }
  55. }
  56.  
  57. bool flag;
  58. protected override void OnBarUpdate()
  59. {
  60.  
  61. try
  62. {
  63. if (!flag)
  64. {
  65. flag = true;
  66. ChartControl.Dispatcher.InvokeAsync(() =>
  67. {
  68. initialize_createGrid();
  69. });
  70. }
  71. }
  72. catch(Exception e)
  73. {
  74. Print(e.ToString());
  75. }
  76. }
  77.  
  78.  
  79.  
  80.  
  81. private System.Windows.Controls.Grid myGrid;
  82. private void initialize_createGrid()
  83. {
  84. try
  85. {
  86. myGrid = new System.Windows.Controls.Grid
  87. {
  88. Name = "MyCustomGrdaid32" + DateTime.Now.ToString("Hms"),
  89. HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
  90. VerticalAlignment = System.Windows.VerticalAlignment.Top
  91. };
  92. int i = -1;
  93.  
  94. System.Windows.Controls.ColumnDefinition column1 = new System.Windows.Controls.ColumnDefinition();
  95. myGrid.ColumnDefinitions.Add(column1);
  96. System.Windows.Controls.ColumnDefinition column2 = new System.Windows.Controls.ColumnDefinition();
  97. myGrid.ColumnDefinitions.Add(column2);
  98. //
  99.  
  100. // ======= WPF TEXTBOX
  101. Brush br = DateTime.Now.Second % 2 == 1 ? Brushes.Green : Brushes.Red;
  102. var newControl = new System.Windows.Controls.TextBox { Name = "asd", Text ="WPF textbox", Width = 100, Background = br };
  103. myGrid.Children.Add(newControl);
  104. i++;
  105. System.Windows.Controls.Grid.SetColumn((UIElement)newControl, i);
  106. //################
  107.  
  108.  
  109. // ======= WinForms TEXTBOX
  110. // %ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\WindowsFormsIntegration.dll
  111. System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
  112. System.Windows.Forms.TextBox txtBox = new System.Windows.Forms.TextBox{ Name = "tb3", Text ="WinForms textbox", Width = 100 };
  113. host.Child = txtBox;
  114. host.Background = Brushes.Yellow;
  115. host.Opacity = 0.5;
  116. host.Name ="dde";
  117. host.Visibility = Visibility.Visible;
  118. host.Child.MouseHover += MouseEvent1;
  119.  
  120.  
  121. myGrid.Children.Add(host);
  122. i++;
  123. System.Windows.Controls.Grid.SetColumn(host, i);
  124. //################
  125.  
  126.  
  127. if (!this.UserControlCollection.Contains(myGrid))
  128. {
  129. this.UserControlCollection.Add(myGrid);
  130. }
  131. }
  132. catch (Exception e)
  133. {
  134. Print(e.ToString());
  135. }
  136. }
  137.  
  138. private void MouseEvent1(object sender, EventArgs e)
  139. {
  140. System.Windows.Forms.MessageBox.Show("a1");
  141. }
  142.  
  143.  
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement