Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How Draw Rectangle Gradient Brush?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How Draw Rectangle Gradient Brush?

    I want draw Rectangle use Gradient Brush.

    Code:
            
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale) {
    LinearGradientBrush linGrBrush = new LinearGradientBrush(System.Windows.Media.Color.FromArgb(255, 255, 0, 0),System.Windows.Media.Color.FromArgb(255, 0, 0, 255), new System.Windows.Point(0, 10),  new System.Windows.Point(200, 10));  
     RenderTarget.FillRectangle(new RectangleF(10, 10, 300, 300),SharpDX.Direct2D1.Brush( linGrBrush)); }
    In line RenderTarget.FillRectangle(new RectangleF(10, 10, 300, 300), SharpDX.Direct2D1.Brush( linGrBrush)); the compiler generates an error.
    How I can use Gradient Brush? How I can draw Rectangle with Gradient Brush?
    Thank you.

    #2
    Hello _Roman,
    Thanks for your post.

    It looks like you need to convert the LinearGradientBrush to be a SharpDX brush using ToDxBrush(). Something like the following snippet seemed to resolve the compile error on my end:
    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
        LinearGradientBrush linGrBrush = new LinearGradientBrush(System.Windows.Media.Color.FromArgb(255, 255, 0, 0),System.Windows.Media.Color.FromArgb(255, 0, 0, 255), new System.Windows.Point(0, 10),  new System.Windows.Point(200, 10));
        SharpDX.Direct2D1.Brush dxBrush = linGrBrush.ToDxBrush(RenderTarget);
        RenderTarget.FillRectangle(new RectangleF(10, 10, 300, 300), dxBrush); 
    }
    Please see the following link for more information on ToDxBrush(): https://ninjatrader.com/support/help..._todxbrush.htm
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JoshG View Post
      It looks like you need to convert the LinearGradientBrush to be a SharpDX brush using ToDxBrush(). Something like the following snippet seemed to resolve the compile error on my end:
      Yes. It is resolved this issue.
      Thank you, very, very very much.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      82 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      43 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      68 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      56 views
      0 likes
      Last Post CarlTrading  
      Working...
      X