ToggleButton
class cAlgo.API
Represents the Toggle button.
Environment behaviour
CLI — not supported. Accepted without error but never displayed, so control events such as Click are never raised.
Cloud — not supported. Accepted without error but never displayed, so control events such as Click are never raised.
Definition
public class ToggleButton : Control
Namespace: cAlgo.API · Group: Controls · Inherits: Control, ControlBase
Examples
using cAlgo.API;
using System;
using System.Linq;
namespace cAlgo
{
// This sample indicator shows how to use ToggleButton control and handle its checked/unchecked events
public partial class ToggleButtonSample : Indicator
{
protected override void Initialize()
{
var stackPanel = new StackPanel
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
BackgroundColor = Color.Gold,
Opacity = 0.7
};
for (int i = 0; i < 5; i++)
{
var toggleButton = new ToggleButton
{
Text = "Toggle Button #" + i + " Unchecked",
Margin = 10
};
toggleButton.Checked += ToggleButton_Checked;
toggleButton.Unchecked += ToggleButton_Unchecked;
stackPanel.AddChild(toggleButton);
}
Chart.AddControl(stackPanel);
}
private void ToggleButton_Checked(ToggleButtonEventArgs obj)
{
var textSplit = obj.ToggleButton.Text.Split(' ').TakeWhile(text => !text.Equals("Unchecked", StringComparison.OrdinalIgnoreCase)).ToArray();
obj.ToggleButton.Text = string.Join(" ", textSplit) + " Checked";
}
private void ToggleButton_Unchecked(ToggleButtonEventArgs obj)
{
var textSplit = obj.ToggleButton.Text.Split(' ').TakeWhile(text => !text.Equals("Checked", StringComparison.OrdinalIgnoreCase)).ToArray();
obj.ToggleButton.Text = string.Join(" ", textSplit) + " Unchecked";
}
public override void Calculate(int index)
{
}
}
}
import clr
clr.AddReference("cAlgo.API")
from cAlgo.API import *
class Test():
def initialize(self):
stackPanel = StackPanel()
stackPanel.HorizontalAlignment = HorizontalAlignment.Center
stackPanel.VerticalAlignment = VerticalAlignment.Center
stackPanel.BackgroundColor = Color.Gold
stackPanel.Opacity = 0.7
for i in range(5):
toggleButton = ToggleButton()
toggleButton.Text = f"Toggle Button # {i} Unchecked"
toggleButton.Margin = Thickness(10)
toggleButton.Checked += self.on_toggle_button_checked
toggleButton.Unchecked += self.on_toggle_button_unchecked
stackPanel.AddChild(toggleButton)
api.Chart.AddControl(stackPanel)
def on_toggle_button_checked(self, args):
textSplit = args.ToggleButton.Text.split(' ')[:4]
args.ToggleButton.Text = f"{' '.join(textSplit)} Checked"
def on_toggle_button_unchecked(self, args):
textSplit = args.ToggleButton.Text.split(' ')[:4]
args.ToggleButton.Text = f"{' '.join(textSplit)} Unchecked"
{
"AccessRights": "None",
"TimeZone": "UTC",
"IsOverlay": true
}
Constructors
| Name | Description |
|---|---|
| ToggleButtonDesktopCLICloud | Initializes a new instance of the Toggle button class. |
Properties
| Name | Description |
|---|---|
BorderColorDesktopCLICloudColor | Gets or sets the border line color. |
BorderThicknessDesktopCLICloudThickness | Gets or sets the border thickness. Property value can be set using Thickness, number, or a string new Thickness(5), new Thickness(1, 2, 3, 4), 5, "5", "1 2 3 4". |
ContentDesktopCLICloudControlBase | Gets or sets the content. |
CornerRadiusDesktopCLICloudCornerRadius | Gets or sets the border corner radius. Property value can be set using CornerRadius, number, or a string: new CornerRadius(5), new CornerRadius(1, 2, 3, 4). |
IsCheckedDesktopCLICloudbool | Defines whether the Toggle button is checked. |
TextDesktopCLICloudstring | Gets or sets the text. |
Events
| Name | Description |
|---|---|
CheckedDesktopCLICloudAction<ToggleButtonEventArgs> | Occurs when checked. |
ClickDesktopCLICloudAction<ToggleButtonEventArgs> | Occurs when clicked. |
UncheckedDesktopCLICloudAction<ToggleButtonEventArgs> | Occurs when unchecked. |
Inherited members
From Control: ForegroundColor, BackgroundColor, Padding, VerticalContentAlignment, HorizontalContentAlignment, FontWeight, FontStyle, FontFamily, FontSize
From ControlBase: ResetProperty, UniqueId, Style, Left, Top, Right, Bottom, Width, Height, MinWidth, MinHeight, MaxWidth, MaxHeight, IsEnabled, IsVisible, Opacity, Margin, VerticalAlignment, HorizontalAlignment, Dock, IsHitTestVisible