Windows Azure Cloud Storage ermöglicht es Ihnen bereits ab 0,10€ pro GB/Monat die Vorteile der Cloud zu nutzen.
Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1549 | Anzahl registrierter User: 1833 | Besucher online: 1537
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

CursorChanger


Autor: dN!3L
Sprache: C#
Bewertung:
4.69 (3 votes)
Anzahl der Aufrufe: 8485
  
Kick it on dotnet-kicks.de  

Beschreibung:

Bietet durch Implementation von IDisposable eine kompakte Möglichkeit, den Cursor für eine bestimmte Zeit zu ändern.
Der ursprünglich angezeigte Cursor wird automatisch wiederhergestellt.


Beispiel:
public class WaitCursorChanger : CursorChanger
{
public WaitCursorChanger(Control control) : base(Cursors.WaitCursor,control)
{ }
}

[...]
private void foo()
{
// Cursor: Default
using (new WaitCursorChanger(this))
{
// Cursor: WaitCursor
using (new CursorChanger(Cursors.Help,this))
{
// Cursor: Help
}
// Cursor: WaitCursor
}
// Cursor: Default
}


Abgelegt unter: Cursor, WaitCursor, Cursors, Control.



C#
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
/// <summary>
/// Bietet durch Implementation von IDisposable eine kompakte Möglichkeit, den Cursor für eine bestimmte Zeit zu ändern.
/// Der ursprünglich angezeigte Cursor wird automatisch wiederhergestellt
/// </summary>
public class CursorChanger : IDisposable
{
	private Cursor rawCursor;	// der ursprüngliche Cursor, der später wiederhergestellt wird
	private Control control;	// das Control für das der Cursor geändert werden soll 


	/// <summary>
	/// Bietet durch Implementation von IDisposable eine kompakte Möglichkeit, den Cursor für eine bestimmte Zeit zu ändern.
	/// Der ursprünglich angezeigte Cursor wird automatisch wiederhergestellt.
	/// </summary>
	/// <param name="cursor">Der Cursor, der gesetzt werden soll.</param>
	/// <param name="control">Ein Control zum setzen des Cursors. <remarks>Ist dieses Control in (einem) anderen Control(s) enthalten, wird der Cursor des Root-Controls geändert</remarks></param>
	/// <example>
	/// public class WaitCursorChanger : CursorChanger
	/// {
	///	public WaitCursorChanger(Control control) : base(Cursors.WaitCursor,control)
	///	{ }
	/// }
	/// 
	/// [...]
	/// private void foo()
	/// {
	///     // Cursor: Default
	///	using (new WaitCursorChanger(this))
	///	{
	///		// Cursor: WaitCursor
	///		using (new CursorChanger(Cursors.Help,this))
	///		{
	///			// Cursor: Help
	///		}
	///		// Cursor: WaitCursor
	///	}
	///	// Cursor: Default
	/// }
	/// </example>
	public CursorChanger(Cursor cursor,Control control)
	{
		this.control = control;

		// den gewünschten Cursor setzen
		Control rootControl = getRootControl(control);
		this.rawCursor = rootControl.Cursor;
		rootControl.Cursor = cursor;
	}


	/// <summary>
	/// Ermittelt das Root-Control
	/// </summary>
	/// <param name="control">Control, dessen Root-Control ermittelt werden soll</param>
	/// <returns>das Root-Control des übergebenen Controls</returns>
	private Control getRootControl(Control control)
	{
		return (control.Parent==null) ? control : getRootControl(control.Parent);
	}


	/// <summary>
	/// Freigeben des Objektes
	/// </summary>
	void IDisposable.Dispose()
	{
		// den ursprünglichen Cursor wiederherstellen
		getRootControl(control).Cursor = rawCursor;
	}
}
Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)



Diese Snippets könnten für Sie interessant sein:
[C#] Maus Sanduhr zeigen wenn Methode ausgeführt wird
[C#] Maus kontrollieren
[C#] Custom Cursor
[C#] Doppelbufferung für Steuerelemente aktivieren
[C#] Transparenter Hintergrund beim Steuerelement
[ASP.net] NullReferenceException
[VB.NET] ControlResize wie in der IDE auch zur Laufzeit
[C#] Generischer Invoker für Windows Form Controls
[ASP.net] Formularelement fokusieren auf Ajax Seiten
[C#] Threadsichere und generische Kommunikation Windows Forms
[C#] Events aus Worker-Thread im GUI-Thread werfen! Kein Invoke!
[C#] Controls gleichen Typs von einem Container in Winform holen
[C#] Eigenschaften aller Steuerlemente eines Formulars setzen
[VB.NET] Alle Textboxen zurücksetzen
[ASP.net] bestimmtes Control auf der aspx-Seite finden
[VB.NET] Oft benötigte Properties von Controls schnell zentral ausfüh
[VB.NET] Das Klick-Event von Controls gemeinsam auffangen und zentral
[VB.NET] Linien u. Kreise a la VB6 - Einfach Zeichnen
[C#] iTunes-ProgressBar
[C#] WaterBox
[VB.NET] Alle Controls einer Form Enablen/Disablen
[C#] Löschen aller TextControls auf einer Form in C#
[VB.NET] Control Resize wie in der IDE auch zur Laufzeit - Extended
[VB.NET] List all controls by using the name of the controls
[C#] Custom Toolstrip Renderer
[C#] Prüfen ob in einem Verzeichnis Schreibrechte verfügbar sind!
[C#] Hochwertige (optisch ansprechende) WPF - Buttons
[C#] WPF - Buttons "OK/Cancel" - endlich unverwechselbar -
[C#] Visuelles Feedback fokussierter Text Boxen

schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.