Siticone Logo
Siticone UI
DOCS
v2025.12.15
Docs Download Button

Siticone Download Button

The SiticoneDownloadButton is an advanced, multi-state control designed to handle and visualize file downloads or long-running asynchronous operations. It acts as a state machine (Idle → Downloading → Completed/Error), handles internal HTTP downloads, visualizes progress, and includes a rich event system for process tracking.

State & Logic

Properties that control the button's internal state machine and how it reacts to progress updates.

Property Type Description & Usage Example
DownloadState DownloadState btn.DownloadState = DownloadState.Downloading; Gets or sets the current mode. Options: Idle, Downloading, Completed, Error, Paused.
AutoManageStateByProgress bool btn.AutoManageStateByProgress = true; If true, the control automatically switches to Downloading when Progress > 0 and Completed when Progress reaches 100.
AutoResetToIdleAtZero bool btn.AutoResetToIdleAtZero = true; If true, setting Progress to 0 resets the state to Idle.
AutoResetAfterCompletion bool btn.AutoResetAfterCompletion = true; If true, the button reverts to Idle automatically after a successful download.
AutoResetDelayMs int btn.AutoResetDelayMs = 2000; Time in milliseconds to wait before auto-resetting after completion.
AllowCancelByClick bool btn.AllowCancelByClick = true; If true, clicking the button during the Downloading state cancels the active operation.

Appearance & Theming

Customize the visual presentation for each state, including gradients, shadows, and icons.

Property Type Description & Usage Example
EnableGradient bool btn.EnableGradient = true;
GradientAngle float btn.GradientAngle = 45f;
IdleColor / IdleColor2 Color Primary and secondary background colors for the Idle state.
DownloadingColor / 2 Color Primary and secondary background colors for the Downloading state.
CompletedColor / 2 Color Primary and secondary background colors for the Completed state.
ErrorColor / 2 Color Primary and secondary background colors for the Error state.
ProgressFillColor Color btn.ProgressFillColor = Color.FromArgb(100, 255, 255, 255);
EnableTextShadow bool btn.EnableTextShadow = true;
TextShadowColor / Offset Color / Point Configuration for the text drop shadow.
EnableIconShadow bool btn.EnableIconShadow = true;
CornerRadius int btn.CornerRadius = 20;

Feedback & Animation

Settings for animations, transitions, and user feedback actions.

Property Type Description & Usage Example
EnableStateTransitions bool btn.EnableStateTransitions = true; Enables smooth color morphing when switching between states.
StateTransitionDuration int btn.StateTransitionDuration = 300;
EnableProgressAnimation bool btn.EnableProgressAnimation = true; Smoothens the movement of the progress bar between values.
UltraPerformanceMode bool btn.UltraPerformanceMode = true; Disables all smooth animations, gradients, and shadows to maximize FPS in heavy UIs.
CompletionAction Enum btn.CompletionAction = DownloadCompletionAction.Shake; Options: None, Shake, Beep, ShakeAndBeep, Notify.
PreviewDownload bool btn.PreviewDownload = true; If true, clicking in Idle state starts a simulated download preview.

Status & Diagnostics

Read-only properties useful for checking the control's runtime status.

Property Type Description
IsBusy bool Returns true if the control is currently performing an operation.
IsDownloadActive bool Returns true if a file download task is actively running.
CurrentUrl string The URL of the file currently being downloaded.
CurrentFilePath string The local file path where the current download is being saved.
IsPreviewActive bool Returns true if the current operation is a simulated preview.
StateChangeTime DateTime The timestamp of the last state transition.

Public Methods

Programmatic control over downloads and state.

StartWebDownloadAsync()
// Initiates an asynchronous file download from a URL.
// Handles HTTP requests, file creation, and progress reporting automatically.
await btnDownload.StartWebDownloadAsync("https://file.zip", "C:\\Downloads\\file.zip");
AttachToAsyncOperation()
// Connects the button to a generic Task that reports progress.
// Useful for database syncs or non-file operations.
await btnDownload.AttachToAsyncOperation(MyLongRunningTask, "Syncing Data");
SetProgressAndState()
// Manually sets the progress and state in one optimized call.
// Bypasses auto-management logic for external control.
btnDownload.SetProgressAndState(50f, DownloadState.Downloading);
Control Methods
// Cancels any active operation and resets the UI immediately.
btnDownload.CancelDownloadAndReset();

// Simulates a fake download for UI testing.
await btnDownload.SimulateDownload(5, "demo_file.exe");

// Updates progress without changing the state logic.
btnDownload.SetProgressWithoutStateChange(75f);

// Manually triggers the error state visualization.
btnDownload.SetError("Connection lost");

Events

Comprehensive event system for tracking the lifecycle.

Event Description & Data
ProgressChanged Fires when progress updates.
Args: Progress, BytesReceived, TotalBytes, DisplayText.
DownloadStateChanged Fires on state transition.
Args: NewState, PreviousState, Reason, Duration.
DownloadCompleted Fires on success.
Args: StartTime, CompletionTime, Duration.
DownloadError Fires on failure.
Args: ErrorMessage, Exception, ProgressAtError.
DownloadIdle Fires when resetting to Idle.
Args: FinalProgress, TotalDuration.

Usage Examples

Example 1: Standard File Download

Downloads a file from the web, saves it locally, and shows a notification on completion.

C# - Web Download
private async void BtnDownload_Click(object sender, EventArgs e)
{
                try
    {
                string url = "https://example.com/installer.msi";
                string path = @"C:\Downloads\installer.msi";

                // Configure for file download
        btnDownload.CompletionAction = DownloadCompletionAction.Notify;
        btnDownload.NotificationTitle = "Download Success";
        btnDownload.NotificationContent = "Installer saved to C:\Downloads";

                // Start the operation
                await btnDownload.StartWebDownloadAsync(url, path);
    }
                catch (Exception ex)
    {
                // Handle startup errors
                MessageBox.Show(ex.Message);
    }
}

Example 2: Custom Async Operation

Uses the button to visualize a non-file task (e.g., syncing data) by attaching it to an async method that reports progress.

C# - Async Task
private async void BtnSync_Click(object sender, EventArgs e)
{
    btnDownload.DownloadText = "Syncing Database...";

                // Define a task that reports progress
                Func<IProgress<float>, CancellationToken, Task> syncTask = 
                async (progressReporter, token) =>
    {
                for (int i = 0; i <= 100; i += 5)
        {
                // Support cancellation via button click
            token.ThrowIfCancellationRequested();

                // Simulate work
                await Task.Delay(100);

                // Update button progress
            progressReporter.Report(i);
        }
    };

                // Attach the task to the button
                await btnDownload.AttachToAsyncOperation(syncTask, "DB Sync");
}

Example 3: Manual Control & External Progress

If you have an existing download mechanism, manually update the button without using its internal downloader.

C# - Manual Control
// 1. Disable auto-management to take full control
btnDownload.AutoManageStateByProgress = false;

void OnExternalDownloadStarted()
{
    btnDownload.DownloadState = DownloadState.Downloading;
}

void OnExternalProgressChanged(int percentage)
{
                // Update progress visual without triggering state logic
    btnDownload.SetProgressWithoutStateChange(percentage);
}

void OnExternalDownloadFinished()
{
    btnDownload.DownloadState = DownloadState.Completed;
                // Manually trigger completion logic
    btnDownload.CompleteDownload();
}

Example 4: Modern Gradient Styling

Configures the button with a modern, gradient-based theme.

C# - Styling
private void ApplyModernTheme()
{
                var btn = siticoneDownloadButton1;
    
                // Enable Gradients
    btn.EnableGradient = true;
    btn.GradientAngle = 45f;
    
                // Idle State: Indigo Gradient
    btn.IdleColor = Color.FromArgb(99, 102, 241);
    btn.IdleColor2 = Color.FromArgb(67, 56, 202);

                // Downloading State: Blue Gradient
    btn.DownloadingColor = Color.FromArgb(59, 130, 246);
    btn.DownloadingColor2 = Color.FromArgb(37, 99, 235);

                // Completed State: Emerald Gradient
    btn.CompletedColor = Color.FromArgb(16, 185, 129);
    btn.CompletedColor2 = Color.FromArgb(5, 150, 105);

                // Text Styling
    btn.EnableTextShadow = true;
    btn.TextShadowColor = Color.FromArgb(50, 0, 0, 0);
    btn.CornerRadius = 25;
}