Window Behavior & Layout

This feature controls how the form’s window behaves, including its closing behavior, drag interactions, and initial positioning.

Overview

This section details the properties and methods that affect the overall window behavior and layout of the form. It covers closing behavior (including countdown and confirmation), window dragging, and positioning (centered or custom).


Key Points

Aspect
Details
Default Value
Example Value

PreventFormClosing

When set to true, clicking the close button does not immediately close the form.

false

true

EnableCloseCountdown

When enabled, a countdown is displayed on the close button before the form closes.

false

true

CloseCountdownDuration

Duration (in seconds) for the close countdown timer.

5 (as per sample code)

3

EnableCloseConfirmation

If true, a confirmation dialog is shown before closing the form.

false

true

DragTitleBar

Allows dragging the form by clicking and dragging on the title bar.

true

false

DragEntireForm

Permits dragging the form from anywhere on its surface.

false

true

StartPosition

Defines the initial position of the form (e.g., CenterScreen).

CenterScreen (set internally)

Manual, CenterScreen

TopMost / IsPinned

Controls whether the form stays on top of other windows (pinned state).

false

true


Best Practices

Recommendation
Explanation
Example in Code

Set StartPosition appropriately

Use CenterScreen to ensure the form is well positioned on launch.

myForm.StartPosition = FormStartPosition.CenterScreen;

Use PreventFormClosing for critical apps

Prevent accidental closure in applications that must remain running (e.g., background utilities).

myForm.PreventFormClosing = true;

Enable confirmation or countdown

Provide users with a chance to cancel closing in critical scenarios.

myForm.EnableCloseConfirmation = true; or myForm.EnableCloseCountdown = true; myForm.CloseCountdownDuration = 5;

Choose drag behavior wisely

Decide between title bar dragging or full-form dragging based on the app design and UX.

myForm.DragTitleBar = true; myForm.DragEntireForm = false;


Common Pitfalls

Issue
Cause
Prevention/Remedy

Form not centering properly

Incorrect setting or overriding of the StartPosition property.

Always set StartPosition before calling Application.Run.

Unexpected closure behavior

Not accounting for the PreventFormClosing or EnableCloseConfirmation settings.

Verify these properties and test the form’s closing logic.

Drag behavior conflicts

Enabling both DragTitleBar and DragEntireForm without proper UX consideration.

Choose one appropriate dragging mode to avoid user confusion.


Usage Scenarios

Scenario
How It Works
Sample Code

Preventing accidental closure

The form does not close immediately when the user clicks the close button, giving room for additional logic or countdown.

csharp\nvar myForm = new SiticoneForm {\n PreventFormClosing = true,\n EnableCloseCountdown = true,\n CloseCountdownDuration = 5\n};\nApplication.Run(myForm);

Dragging from the title bar

The user can click and drag only from the title bar area to move the form around the screen.

csharp\nvar myForm = new SiticoneForm {\n DragTitleBar = true,\n DragEntireForm = false\n};\nApplication.Run(myForm);

Centering the form on screen

When the StartPosition is set to CenterScreen, the form appears centered regardless of the screen size.

csharp\nvar myForm = new SiticoneForm {\n StartPosition = FormStartPosition.CenterScreen\n};\nApplication.Run(myForm);


Real Life Usage Scenarios

Scenario
Explanation
How to Implement

Kiosk Applications

In kiosk mode, accidental closure must be prevented and the form must be centrally positioned.

Set PreventFormClosing = true, EnableCloseConfirmation = true, and StartPosition = CenterScreen in the form’s constructor.

Utility Applications

A utility app running in the background may need to be draggable by its title bar only.

Set DragTitleBar = true and ensure DragEntireForm = false to maintain controlled movement.

Applications with Critical Data

Applications dealing with sensitive data might need confirmation before closure to avoid data loss.

Set EnableCloseConfirmation = true and provide meaningful CloseConfirmationTitle and CloseConfirmationMessage.


Troubleshooting Tips

Problem
Potential Cause
Suggested Fix

Form not responding to drag events

The drag properties might be misconfigured or overridden in the form’s initialization.

Verify that DragTitleBar and DragEntireForm are set as intended and check for conflicts in the constructor logic.

Unexpected behavior when closing

Countdown or confirmation settings are interfering with the close event.

Double-check the values of PreventFormClosing, EnableCloseCountdown, and EnableCloseConfirmation properties.

Form appears off-center

Custom layout logic may override the StartPosition or manual centering logic.

Ensure that StartPosition is properly set to CenterScreen before the form is loaded.


Review

Aspect
Notes

Flexibility

The code provides extensive control over window behavior, allowing fine-tuning per scenario.

Integration Complexity

While properties are numerous, grouping them logically makes integration straightforward.

User Experience

Features like drag behavior, closing confirmation, and countdown enhance UX when used appropriately.


Summary

Summary Point
Description

Comprehensive Control

The form exposes multiple properties to manage closing behavior, dragging, and positioning.

Enhanced User Safety

Features such as closing confirmation and countdown help avoid accidental closures.

Adaptability to Various Scenarios

Whether used in kiosk apps, utility tools, or sensitive data applications, the window layout features are versatile.


Additional Code Example

Below is a complete integration sample demonstrating how to initialize a SiticoneForm with customized window behavior and layout:

using System;
using System.Windows.Forms;
using SiticoneNetFrameworkUI; // Ensure your namespace is referenced appropriately

public class MainForm
{
    public static void Main()
    {
        var myForm = new SiticoneForm
        {
            FormTitle = "My Custom Application",
            StartPosition = FormStartPosition.CenterScreen,
            DragTitleBar = true,
            DragEntireForm = false,
            PreventFormClosing = false,
            EnableCloseCountdown = true,
            CloseCountdownDuration = 5,
            EnableCloseConfirmation = true,
            // Other properties can be set here as needed
        };

        // Optional: Subscribe to events
        myForm.FormClosing += (sender, e) =>
        {
            // Additional logic before closing
            Console.WriteLine("The form is closing. Cleaning up resources...");
        };

        myForm.HelpButtonClicked += (sender, e) =>
        {
            MessageBox.Show("Help button clicked. Displaying help information...");
        };

        Application.Run(myForm);
    }
}

Additional Resources

Resource
Description
Link/Reference

Code Comments

Inline comments within the code provide additional context for each property and method.

Refer to the provided code snippet.

Developer Forum

Community discussions and troubleshooting tips can enhance understanding of these features.

Check relevant .NET/WinForms forums.

Official Documentation

Microsoft’s documentation on WinForms and form behavior provides deeper insights.


This documentation should serve as a comprehensive guide for integrating and customizing the window behavior and layout of your SiticoneForm. Each section is designed to help developers understand the options available, follow best practices, and avoid common pitfalls while implementing the feature.

Last updated