Skip to content

Commit 96228c2

Browse files
authored
Merge pull request #648 from telerik/new-kb-spreadprocessing-simulating-checkbox-conditional-formatting-d0a221a8ec624ceda1ec23aeec4bdd0b
Added new kb article spreadprocessing-simulating-checkbox-conditional-formatting
2 parents 5558782 + 55d36d4 commit 96228c2

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: Resolving Unexpected Per-Monitor DPI Awareness in WinForms Apps
3+
description: Fix a WinForms application that unexpectedly becomes (per‑monitor) DPI aware and changes size when using controls depending on the Telerik Document Processing libraries.
4+
type: how-to
5+
page_title: Why Your WinForms App Resizes - DPI Awareness and Telerik Document Processing Explained
6+
slug: fix-winforms-runtime-dpi-aware-application
7+
position: 0
8+
tags: winforms,windows, forms, dpi, scaling, document, processing, pdf, viewer, rich, text, editor, spreadsheet, control, aware, shrink, scale
9+
res_type: kb
10+
---
11+
12+
## Environment
13+
14+
|Product Version|Product|Author|
15+
|----|----|----|
16+
|All|Document Processing Libraries|[Yoan Karamanov](https://www.telerik.com/blogs/author/yoan-karamanov)|
17+
18+
## Description
19+
20+
A WinForms application may appear smaller (or larger) at runtime after using [Document Processing Libraries]({%slug introduction%}) (**DPL**) functionality or [DPL-dependent Telerik controls](https://docs.telerik.com/devtools/winforms/integration-with-other-telerik-products/document-processing-libraries#telerik-ui-for-winforms-integration) (e. g. **RadPdfViewer**, **RadSpreadsheet**). This can occur, for example, when **exporting data**, loading a document, or instantiating types from assemblies used by:
21+
22+
These dependencies internally rely on WPF assemblies where DPI awareness is enabled at the assembly level. The moment a type from such an assembly is initialized, the hosting WinForms process can become DPI-aware.
23+
24+
## Solution
25+
26+
You can choose between two approaches:
27+
28+
### 1. Make the application explicitly DPI-aware
29+
30+
With this approach your app will look smaller when started. It will not look blurry on HDPI displays. Detailed information is available in the [DPI Support](https://docs.telerik.com/devtools/winforms/telerik-presentation-framework/dpi-support) article.
31+
32+
### 2. Keep (or force) the application DPI-unaware (Windows 10 only)
33+
34+
This approach works only on Windows 10. If you intend to use your application on machines where the DPI scaling is larger than 100 percent, you should explicitly set the application to be DPI-unaware
35+
36+
#### [C#] Force process DPI unaware before using a Document Processing type
37+
38+
```csharp
39+
private void workbookTestButton_Click(object sender, EventArgs e)
40+
{
41+
SetProcessDpiAwareness(_Process_DPI_Awareness.Process_DPI_Unaware);
42+
Workbook wb = new Workbook();
43+
}
44+
45+
[DllImport("shcore.dll")]
46+
static extern int SetProcessDpiAwareness(_Process_DPI_Awareness value);
47+
48+
enum _Process_DPI_Awareness
49+
{
50+
Process_DPI_Unaware = 0,
51+
Process_System_DPI_Aware = 1,
52+
Process_Per_Monitor_DPI_Aware = 2
53+
}
54+
```
55+
56+
>note None of the above approaches affect the application when the scaling is set to 100%.
57+
58+
## See Also
59+
60+
* [DPI Support](https://docs.telerik.com/devtools/winforms/telerik-presentation-framework/dpi-support)
2.6 KB
Loading
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
title: Simulating a Checkbox with Conditional Formatting in Telerik SpreadProcessing
3+
description: Learn how to simulate a checkbox using conditional formatting with Telerik SpreadProcessing.
4+
type: how-to
5+
page_title: Simulating a Checkbox Using Conditional Formatting with Telerik SpreadProcessing
6+
meta_title: Simulating a Checkbox Using Conditional Formatting with Telerik SpreadProcessing
7+
slug: spreadprocessing-simulating-checkbox-conditional-formatting
8+
tags: spread, processing, conditional, formatting, check, box, telerik, document, xlsx
9+
res_type: kb
10+
ticketid: 1667088
11+
---
12+
13+
## Environment
14+
15+
|Product Version|Product|Author|
16+
|----|----|----|
17+
|2025.3.806|[SpreadProcessing]({%slug radspreadprocessing-overview%})|[Yoan Karamanov](https://www.telerik.com/blogs/author/yoan-karamanov)|
18+
19+
## Description
20+
21+
This article describes how to use the [SpreadProcessing]({%slug radspreadprocessing-overview%}) library to simulate a checkbox by using conditional formatting rules. The goal is to display a checked symbol (☑) when the cell value is **1** and an unchecked symbol (☐) when the cell value is **0**.
22+
23+
This knowledge base article also answers the following questions:
24+
- How to simulate checkbox behavior in Telerik SpreadProcessing?
25+
- How to use conditional formatting for representing checkboxes?
26+
- How to display different symbols based on cell values in Telerik SpreadProcessing?
27+
28+
## Solution
29+
30+
To simulate a checkbox using conditional formatting in Telerik SpreadProcessing, apply two separate conditional formatting rules: one for the `checked` state and one for the `unchecked` state.
31+
32+
1. Create a [Workbook]({%slug radspreadprocessing-working-with-workbooks-what-is-workbook%}) and add a worksheet.
33+
2. Define a [DifferentialFormatting]({%slug radspreadprocessing-features-conditional-formatting%}) for the checked state with a format that displays "☑".
34+
3. Create an **EqualToRule** for the checked state, matching cells with a value of **1**.
35+
4. Apply the conditional formatting rule to the cell.
36+
5. Define another **DifferentialFormatting** for the unchecked state with a format that displays "☐".
37+
6. Create an **EqualToRule** for the unchecked state, matching cells with a value of **0**.
38+
7. Apply the second conditional formatting rule to the cell.
39+
8. Set the cell value to **1** or **0** to test the checkbox simulation.
40+
9. Export the workbook to an XLSX file.
41+
42+
![Conditional Formatting CheckBox](images/conditional-formatting-checkbox.png)
43+
44+
Here’s an example implementation:
45+
46+
```csharp
47+
Workbook workbook = new Workbook();
48+
Worksheet worksheet = workbook.Worksheets.Add();
49+
50+
// Define formatting for checked state
51+
DifferentialFormatting checkedFormatting = new DifferentialFormatting();
52+
checkedFormatting.CellValueFormat = new CellValueFormat("");
53+
EqualToRule checkedRule = new EqualToRule("1", checkedFormatting);
54+
ConditionalFormatting checkedConditionalFormatting = new ConditionalFormatting(checkedRule);
55+
worksheet.Cells[0, 0].AddConditionalFormatting(checkedConditionalFormatting);
56+
57+
// Define formatting for unchecked state
58+
DifferentialFormatting uncheckedFormatting = new DifferentialFormatting();
59+
uncheckedFormatting.CellValueFormat = new CellValueFormat("");
60+
EqualToRule uncheckedRule = new EqualToRule("0", uncheckedFormatting);
61+
ConditionalFormatting uncheckedConditionalFormatting = new ConditionalFormatting(uncheckedRule);
62+
worksheet.Cells[0, 0].AddConditionalFormatting(uncheckedConditionalFormatting);
63+
64+
// Set initial value to simulate checkbox
65+
worksheet.Cells[0, 0].SetValue(1);
66+
67+
// Export workbook to XLSX file
68+
string xlsxOutputPath = "output.xlsx";
69+
IWorkbookFormatProvider xlsxFormatProvider = new XlsxFormatProvider();
70+
71+
using (Stream output = new FileStream(xlsxOutputPath, FileMode.Create))
72+
{
73+
xlsxFormatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
74+
}
75+
```
76+
77+
## See Also
78+
79+
* [Conditional Formatting]({%slug radspreadprocessing-features-conditional-formatting%})
80+
* [Workbook]({%slug radspreadprocessing-working-with-workbooks-what-is-workbook%})
81+
* [Using XlsxFormatProvider]({%slug radspreadprocessing-formats-and-conversion-xlsx-xlsxformatprovider%})

0 commit comments

Comments
 (0)