CodeKeep C# Feed Luglio 16th, 2008
Description: This is a child of the ListView class that has alternating background colors
Dependency Properties are used to set the colors of the alternating background
All instantiated classes are explicitly declared in their specific namespaces.
Link:
http://www.codekeep.net/snippets/f7f17e5c-7ad3-4f04-a4a1-e6c6eff04db3.aspx/// <summary>
/// Alternates the BG Color of each item in the listview
/// </summary>
public class AltBGRowsListView : System.Windows.Controls.ListView {
protected override void PrepareContainerForItemOverride(System.Windows.DependencyObject element, object item) {
base.PrepareContainerForItemOverride(element, item);
if (View is System.Windows.Controls.GridView) {
int index = ItemContainerGenerator.IndexFromContainer(element);
System.Windows.Controls.ListViewItem lvi = element as System.Windows.Controls.ListViewItem;
if (0 == index % 2)
lvi.Background = this.GetValue(AltBGRowsListView.FirstRowProperty) as System.Windows.Media.SolidColorBrush;
else
lvi.Background = this.GetValue(AltBGRowsListView.SecondRowProperty) as System.Windows.Media.SolidColorBrush;
}
}
public static readonly System.Windows.DependencyProperty FirstRowProperty = System.Windows.DependencyProperty.Register("FirstRow", typeof(System.Windows.Media.SolidColorBrush), typeof(AltBGRowsListView), new System.Windows.UIPropertyMetadata(null));
/// <summary>
/// Sets the color of the 1st of the alternating rows
/// </summary>
public System.Windows.Media.SolidColorBrush FirstRow {
get {
return (System.Windows.Media.SolidColorBrush)GetValue(FirstRowProperty);
}
set {
SetValue(FirstRowProperty, value);
}
}
public static readonly System.Windows.DependencyProperty SecondRowProperty = System.Windows.DependencyProperty.Register("SecondRow", typeof(System.Windows.Media.SolidColorBrush), typeof(AltBGRowsListView), new System.Windows.UIPropertyMetadata(null));
/// <summary>
/// Sets the 2nd color of the alternating rows
/// </summary>
public System.Windows.Media.SolidColorBrush SecondRow {
get {
return (System.Windows.Media.SolidColorBrush)GetValue(SecondRowProperty);
}
set {
SetValue(SecondRowProperty, value);
}
}
}
CodeKeep C# Feed Luglio 16th, 2008
Description: Makes a date time picker drop down when mouse hovers over it
Link:
http://www.codekeep.net/snippets/3da21bc1-7cf2-4f69-9c4c-788d45a9b006.aspxprivate void dtpFrom_MouseHover(object sender, EventArgs e)
{
dtpFrom.Focus();
SendKeys.SendWait("%{DOWN}");
}
CodeKeep C# Feed Luglio 16th, 2008
Description: WaitCursor Class
Link:
http://www.codekeep.net/snippets/67dbf1bc-8bb9-4255-98cb-6a4149582cee.aspxpublic class WaitCursor : IDisposable
{
public WaitCursor()
{
Cursor.Current = Cursors.WaitCursor;
}
public void Dispose()
{
Cursor.Current = Cursors.Default;
}
}
CodeKeep C# Feed Luglio 16th, 2008
Description: GetPostBackEventHandler
Link:
http://www.codekeep.net/snippets/25390c9f-dbc4-4337-bed9-723c9e003f39.aspx if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowType != DataControlRowType.EmptyDataRow)
{
bool isLockedOut= bool.Parse( DataBinder.Eval( e.Row.DataItem, "IsLockedOut").ToString());
bool isOnline = bool.Parse( DataBinder.Eval( e.Row.DataItem, "IsOnline").ToString());
string userName = DataBinder.Eval( e.Row.DataItem, "UserName").ToString();
e.Row.Attributes.Add("onMouseOver", "DoMarkOn(this);");
e.Row.Attributes.Add("onMouseOut", "DoMarkOff(this);");
TamperProof tp = new TamperProof();
string url = string.Format("DetailUserView.aspx?username={0}", tp.QueryStringEncode( userName ));
PostBackOptions postBackOptions = new PostBackOptions(MembersGridView, string.Empty, url, true, true, false, true, false, string.Empty);
e.Row.Attributes.Add("onclick",ClientScript.GetPostBackEventReference( postBackOptions ));
Image IsLockedOutImage = e.Row.FindControl("IsLockedOutImage") as Image;
Image IsOnlineImage = e.Row.FindControl("IsOnlineImage") as Image;
IsLockedOutImage.ImageUrl = string.Format("~/App_Themes/Office2007/images/{0}", isLockedOut ? "user1_lock.png" : "lock_open.png" );
IsLockedOutImage.AlternateText = isLockedOut ? Resources.Admin.Locked : Resources.Admin.UnLocked;
IsOnlineImage.Visible = isOnline;
}
CodeKeep C# Feed Luglio 16th, 2008
Description: Start-Routine for a Application where should only be start one Instance. The Programm use the Multiplexer
in the System.Threading.Assembly
Link:
http://www.codekeep.net/snippets/393c0960-573e-47a4-a2e3-463015cbe8fe.aspxstatic void Main()
{
bool bCreatedNew = false;
// Multiplexer erzeugen der überprüft ob die Applikation gestartet wurde. Der out Parameter
// wird nur beim ERSTEN erfolgreichen Start gesetzt.
Mutex mtxApp = new System.Threading.Mutex(true, Application.ProductName, out bCreatedNew);
// Wenn die Erzeugung erfolgreich war.
if (bCreatedNew)
{
Application.Run(new FMAIN());
// Mutex wieder freigeben
mtxApp.ReleaseMutex();
}
else
{
string msg = String.Format("Das Programm \"{0}\" wurde bereits gestartet!", Application.ProductName);
MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
CodeKeep C# Feed Luglio 16th, 2008
Description: Die Funktion wandelt einen übergebenen String in einen codierten MD5 Hashstring um und gibt ihn zurück.
Die Umwandlung ist unidirektional, d.h. der String kann nicht mehr rückgewandelt werden.
Link:
http://www.codekeep.net/snippets/9c3de3fb-6ad5-4a15-8d97-f9df8c34aa63.aspx protected internal string MD5HashString(string sTextToHash)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] byValue;
byte[] byHash;
// Neues CryptoServiceProvider Objekt erzeugen
byValue = System.Text.Encoding.UTF8.GetBytes(sTextToHash);
// Berechne den Hash und schreibe ein Array von Bytes zurück
byHash = md5.ComputeHash(byValue);
// Provider löschen
md5.Clear();
// Gibt einen Base 64 codierten String mit dem Hashwert zurück
return Convert.ToBase64String(byHash);
}
maurodx Luglio 16th, 2008
Take a look at this faboulos offers! Computer voip and so on!