My favorites | Sign in
Project Logo
                
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
// Copyright 2005-2009 Gallio Project - http://www.gallio.org/
// Portions Copyright 2000-2004 Jonathan de Halleux
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Gallio.Common.Platform;

namespace Gallio.UI.Controls
{
/// <summary>
/// An extension of the Button class that displays the "Shield" icon when
/// privilege elevation is required.
/// </summary>
public class ShieldButton : Button
{
private bool shield;

/// <summary>
/// Creates a shield button.
/// </summary>
public ShieldButton()
{
FlatStyle = FlatStyle.System;
}

/// <summary>
/// An event raised when the value of <see cref="Shield" /> has changed.
/// </summary>
public event EventHandler ShieldChanged;

/// <summary>
/// Gets or sets whether the shield icon should be displayed.
/// </summary>
public bool Shield
{
get { return shield; }
set
{
if (value != shield)
{
shield = value;
UpdateShield();
OnShieldChanged(EventArgs.Empty);
}
}
}

/// <summary>
/// Raises the <see cref="ShieldChanged" /> event.
/// </summary>
/// <param name="e">The event arguments.</param>
protected virtual void OnShieldChanged(EventArgs e)
{
if (ShieldChanged != null)
ShieldChanged(this, e);
}

private void UpdateShield()
{
if (! DotNetRuntimeSupport.IsUsingMono)
{
Native.SendMessage(new HandleRef(this, Handle), Native.BCM_SETSHIELD,
new IntPtr(0), new IntPtr(shield ? 1 : 0));
}
}
}
}
Show details Hide details

Change log

r1997 by yann.trevin on Jul 15, 2009   Diff
Added some rules to the XML doc
verification scripts (mostly to detect
empty elements)
Fixed a plethora of bugs and typos in the
XML doc.
Go to: 
Project members, sign in to write a code review

Older revisions

r1857 by jeff.brown on May 26, 2009   Diff
Sync'd the VS 2010 projects.
Added missing license boilerplate.
r1856 by jeff.brown on May 26, 2009   Diff
Added support for executing commands
with privilege elevation.  On Vista,
this causes a UAC prompt to be
displayed when administrative
credentials are required.
...
All revisions of this file

File info

Size: 2592 bytes, 82 lines
Hosted by Google Code