Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Program.cs « PrusaSL1Viewer - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e1bc5d1e2b473cc69f8b82b1bc341af0b7f753b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 *                     GNU AFFERO GENERAL PUBLIC LICENSE
 *                       Version 3, 19 November 2007
 *  Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
 *  Everyone is permitted to copy and distribute verbatim copies
 *  of this license document, but changing it is not allowed.
 */
using System;
using System.Drawing;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;
using PrusaSL1Reader;

namespace PrusaSL1Viewer
{
    static class Program
    {
        /// <summary>
        /// Changes fonts of controls contained in font collection recursively. <br/>
        /// <b>Usage:</b> <c><br/>
        /// SetAllControlsFont(this.Controls, 20); // This makes fonts 20% bigger. <br/>
        /// SetAllControlsFont(this.Controls, -4, false); // This makes fonts smaller by 4.</c>
        /// </summary>
        /// <param name="ctrls">Control collection containing controls</param>
        /// <param name="amount">Amount to change: posive value makes it bigger, 
        /// negative value smaller</param>
        /// <param name="amountInPercent">True - grow / shrink in percent, 
        /// False - grow / shrink absolute</param>
        /// <param name="amountType">0 = Absolute | 1 = Partial | 2 = Percent</param>
        public static void SetAllControlsFontSize(
            Control.ControlCollection ctrls,
            int amount = 0, byte amountType = 0)
        {
            if (amount == 0) return;
            foreach (Control ctrl in ctrls)
            {
                // recursive
                SetAllControlsFontSize(ctrl.Controls, amount, amountType);

                var oldSize = ctrl.Font.Size;
                float newSize;
                switch (amountType)
                {
                    case 1:
                        newSize = oldSize + amount;
                        break;
                    case 2:
                        newSize = oldSize + oldSize * (amount / 100);
                        break;
                    default:
                        newSize = amount;
                        break;
                }
                
                if (newSize < 8) newSize = 8; // don't allow less than 8
                var fontFamilyName = ctrl.Font.FontFamily.Name;
                var fontStyle = ctrl.Font.Style;
                ctrl.Font = new Font(fontFamilyName, newSize, fontStyle);
            };
        }

        public static FileFormat SlicerFile { get; set; }
        public static FrmMain FrmMain { get; private set; }
        public static FrmAbout FrmAbout { get; private set; }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            FrmMain = new FrmMain();
            FrmAbout = new FrmAbout();

            Application.Run(FrmMain);
        }
    }
}