aboutsummaryrefslogtreecommitdiff
path: root/Histacom2.Engine/UI/ClassicDropDown.cs
blob: 93b4a62abaaed5fc55777878d396d6a5f9f62451 (plain) (blame)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Histacom2.Engine.Template;

namespace Histacom2.Engine.UI
{
    public partial class ClassicDropDown : UserControl
    {
        public DropDownOverlay thisOverlay = new DropDownOverlay();
        public bool UseSystemPasswordChar { get; set; }
        public bool dropDownShown;

        public override string Text
        {
            get
            {
                return textBox1.Text;
            }
            set
            {
                textBox1.Text = value;
            }
        }

        public static Color textboxcolor = Color.Black;

        public static Color _lightBack = Color.Silver;
        public static Color _darkBack = Color.Silver;

        public List<string> items = new List<string> { "TestItem" };

        public ClassicDropDown()
        {
            InitializeComponent();

            
            try
            {
                // Draw the border    

                this.Paint += new PaintEventHandler((object sender, PaintEventArgs e) =>
                {
                    // Update a bunch of variables!
                    textBox1.Font = Font;

                    if (SaveSystem.currentTheme != null)
                    {
                        textBox1.BackColor = SaveSystem.currentTheme.threeDObjectsColor;
                        BackColor = SaveSystem.currentTheme.threeDObjectsColor;

                        textboxcolor = SaveSystem.currentTheme.windowColor;

                        _lightBack = Paintbrush.GetLightFromColor(textboxcolor);
                        _darkBack = Paintbrush.GetDarkFromColor(textboxcolor);
                    }
                    else
                    {
                        textBox1.BackColor = Color.White;
                        BackColor = Color.White;
                    }
                });

                

                tborder.Paint += new PaintEventHandler((object sender, PaintEventArgs e) =>
                {
                    e.Graphics.DrawLine(new Pen(_darkBack), 0, 0, tborder.Width, 0);
                    e.Graphics.DrawLine(Pens.Black, 0, 1, tborder.Width, 1);

                });

                lborder.Paint += new PaintEventHandler((object sender, PaintEventArgs e) =>
                {
                    e.Graphics.DrawLine(new Pen(_darkBack), 0, 0, 0, Height);
                    e.Graphics.DrawLine(Pens.Black, 1, 0, 1, Height);
                });

                rborder.Paint += new PaintEventHandler((object sender, PaintEventArgs e) =>
                {
                    e.Graphics.DrawLine(new Pen(_lightBack), 0, 0, 0, Height - 1);
                    e.Graphics.DrawLine(new Pen(textboxcolor), 1, 0, 1, Height - 1);
                });

                bborder.Paint += new PaintEventHandler((object sender, PaintEventArgs e) =>
                {
                    e.Graphics.DrawLine(new Pen(_lightBack), 0, 0, Width - 1, 0);
                    e.Graphics.DrawLine(new Pen(textboxcolor), 0, 1, Width - 2, 1);
                });

                tborder.Invalidate();
                lborder.Invalidate();
                rborder.Invalidate();
                bborder.Invalidate();
            }
            catch { }
        }

        public void ChooseItem(string str)
        {
            textBox1.Text = str;
            ShowHideDropDown();
        }

        public void ShowHideDropDown()
        {
            if (dropDownShown)
            {
                thisOverlay.Close();
                dropDownShown = false;
            } else {
                thisOverlay = new DropDownOverlay();
                int applyHeight = 0;
                foreach (string str in items)
                {
                    DropDownItem itm = new DropDownItem();
                    itm.ChangeText(str, Font);
                    itm.dpdw = this;
                    itm.Dock = DockStyle.Top;
                    applyHeight += itm.Height;
                    thisOverlay.outline.Controls.Add(itm);
                }
                thisOverlay.outline.Location = this.PointToScreen(Point.Empty);
                thisOverlay.outline.Top += this.Height;
                thisOverlay.outline.Size = new Size(this.Width, applyHeight);

                thisOverlay.Deactivate += (sender2, e2) => { thisOverlay.Close(); dropDownShown = false; };

                thisOverlay.Show();
                dropDownShown = true;
            }
        }

        private void dropDownSwitch_Click(object sender, EventArgs e)
        {
            ShowHideDropDown();
        }

        private void ClassicDropDown_Load(object sender, EventArgs e)
        {
            try
            {
                ((Form)this.TopLevelControl).FormClosed += (sender2, e2) => { thisOverlay.Close(); };
                ((Form)this.TopLevelControl).Resize += (sender2, e2) =>
                {
                    thisOverlay.outline.Location = this.PointToScreen(Point.Empty);
                    thisOverlay.outline.Top += this.Height;
                    thisOverlay.BringToFront();
                };

                ((Form)this.TopLevelControl).Move += (sender2, e2) =>
                {
                    thisOverlay.outline.Location = this.PointToScreen(Point.Empty);
                    thisOverlay.outline.Top += this.Height;
                    thisOverlay.BringToFront();
                };
            } catch { }
            
        }
    }
}