FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CefSharp/CefSharp.WinForms.Example/ControlExtensions.cs at master · SkyNetStudio/CefSharp · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
SkyNetStudio
/
CefSharp
Public
forked from
cefsharp/CefSharp
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
CefSharp
/
CefSharp.WinForms.Example
/
ControlExtensions.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
76 lines (67 loc) · 2.44 KB
Breadcrumbs
CefSharp
/
CefSharp.WinForms.Example
/
ControlExtensions.cs
Copy path
File metadata and controls
76 lines (67 loc) · 2.44 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// Copyright © 2019 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using
System
;
using
System
.
Windows
.
Forms
;
namespace
CefSharp
.
WinForms
.
Example
{
public
static
class
ControlExtensions
{
/// <summary>
/// Finds the parent for the given control of <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">Type</typeparam>
/// <param name="control">control</param>
/// <returns>Parent or null</returns>
public
static
T
GetParentOfType
<
T
>
(
this
Control
control
)
where
T
:
Control
{
if
(
control
.
IsDisposed
||
!
control
.
IsHandleCreated
)
{
return
default
;
}
var
current
=
control
;
do
{
current
=
current
.
Parent
;
if
(
current
==
null
)
{
return
default
;
}
}
while
(
current
.
GetType
(
)
!=
typeof
(
T
)
)
;
return
(
T
)
current
;
}
/// <summary>
/// Executes the Action asynchronously on the UI thread, does not block execution on the calling thread.
/// No action will be performed if the control doesn't have a valid handle or the control is Disposed/Disposing.
/// </summary>
/// <param name="control">the control for which the update is required</param>
/// <param name="action">action to be performed on the control</param>
public
static
void
InvokeOnUiThreadIfRequired
(
this
Control
control
,
Action
action
)
{
//See https://stackoverflow.com/questions/1874728/avoid-calling-invoke-when-the-control-is-disposed
//for background and some guidance when implementing your own version.
//No action
if
(
control
.
Disposing
||
control
.
IsDisposed
||
!
control
.
IsHandleCreated
)
{
return
;
}
if
(
control
.
InvokeRequired
)
{
control
.
BeginInvoke
(
(
Action
)
(
(
)
=>
{
//No action
if
(
control
.
Disposing
||
control
.
IsDisposed
||
!
control
.
IsHandleCreated
)
{
return
;
}
action
(
)
;
}
)
)
;
}
else
{
action
.
Invoke
(
)
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL