-
Notifications
You must be signed in to change notification settings - Fork 3
/
CookiesTextBox.cs
146 lines (115 loc) · 3.16 KB
/
CookiesTextBox.cs
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
using System;
using System.ComponentModel;
using System.Windows.Forms;
// Reading cookies from Internet Explorer
// https://www.cyotek.com/blog/reading-cookies-from-internet-explorer
// Copyright © 2019 Cyotek Ltd. All Rights Reserved.
// This source code is licensed under the Creative Commons Attribution 4.0 International License.
// To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.
// Found this example useful?
// https://www.paypal.me/cyotek
namespace Cyotek.Demonstrations.InternetGetCookieEx
{
[DefaultProperty(nameof(Cookies))]
[DefaultEvent(nameof(CookiesChanged))]
internal class CookiesTextBox : TextBox
{
#region Constants
private static readonly object _eventCookiesChanged = new object();
#endregion
#region Fields
private string _cookies;
#endregion
#region Constructors
public CookiesTextBox()
{
base.ReadOnly = true;
base.Multiline = true;
base.ScrollBars = ScrollBars.Both;
base.WordWrap = false;
}
#endregion
#region Events
/// <summary>
/// Occurs when the Cookies property value changes
/// </summary>
[Category("Property Changed")]
public event EventHandler CookiesChanged
{
add { this.Events.AddHandler(_eventCookiesChanged, value); }
remove { this.Events.RemoveHandler(_eventCookiesChanged, value); }
}
#endregion
#region Properties
[Category("Appearance")]
[DefaultValue("")]
public string Cookies
{
get { return _cookies; }
set
{
if (_cookies != value)
{
_cookies = value;
this.OnCookiesChanged(EventArgs.Empty);
}
}
}
[DefaultValue(true)]
public override bool Multiline
{
get { return base.Multiline; }
set { base.Multiline = value; }
}
[DefaultValue(true)]
public new bool ReadOnly
{
get { return base.ReadOnly; }
set { base.ReadOnly = value; }
}
[DefaultValue(typeof(ScrollBars), "Both")]
public new ScrollBars ScrollBars
{
get { return base.ScrollBars; }
set { base.ScrollBars = value; }
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string Text
{
get { return base.Text; }
set { base.Text = value; }
}
[DefaultValue(false)]
public new bool WordWrap
{
get { return base.WordWrap; }
set { base.WordWrap = value; }
}
#endregion
#region Methods
/// <summary>
/// Raises the <see cref="CookiesChanged" /> event.
/// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnCookiesChanged(EventArgs e)
{
EventHandler handler;
this.SetCookieText();
handler = (EventHandler)this.Events[_eventCookiesChanged];
handler?.Invoke(this, e);
}
private void SetCookieText()
{
if (!string.IsNullOrEmpty(_cookies))
{
base.Text = _cookies.Replace("; ", Environment.NewLine);
}
else
{
base.Text = string.Empty;
}
}
#endregion
}
}