CodeKeep C# Feed Agosto 6th, 2008
Description: Part 2 0f 2 to make the Task bar blink in a separate class file. Written by Hawkstalon
Link:
http://www.codekeep.net/snippets/29ba21f9-f225-444c-aae6-1e506da4e808.aspxusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UI.Tools;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
private bool alertRaised = false;
private bool _blink = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void alert_Tick(object sender, EventArgs e)
{
if (!alertRaised)
{
//blink.Interval = 500;
//blink.Enabled = true;
//blink.Start();
UI.Tools.Forms.FlashWindowEx(this.Handle, Forms.dwFlags.FLASHW_ALL, 20, 0);
alertRaised = true;
}
}
private void blink_Tick(object sender, EventArgs e)
{
if (!_blink)
{
//FlashWindow(this.Handle, true);
//FlashWindowEx(this.Handle);
_blink = true;
}
else
{
//FlashWindow(this.Handle, false);
_blink = false;
}
}
private void Form1_Activated(object sender, EventArgs e)
{
alertRaised = false;
alert.Interval = 10000;
alert.Stop();
alert.Enabled = false;
UI.Tools.Forms.FlashWindowEx(this.Handle, Forms.dwFlags.FLASHW_STOP, 0, 0);
//blink.Stop();
//blink.Enabled = false;
}
private void Form1_Deactivate(object sender, EventArgs e)
{
alert.Interval = 10000;
alert.Enabled = true;
alert.Start();
}
}
}
CodeKeep C# Feed Agosto 6th, 2008
Description: this is a separate class to make your taskbar blink this is piece of 1 of 2.
Link:
http://www.codekeep.net/snippets/04a632d2-d86c-4bd2-bca7-120cdec1698a.aspxusing System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace UI.Tools
{
public class Forms
{
[DllImport("USER32.DLL", EntryPoint = "FlashWindowEx")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
public UInt32 cbSize;
public IntPtr hwnd;
public UInt32 dwFlags;
public UInt32 uCount;
public UInt32 dwTimeout;
}
public enum dwFlags
{
//Stop flashing. The system restores the window to its original state.
FLASHW_STOP = 0,
//Flash the window caption.
FLASHW_CAPTION = 1,
//Flash the taskbar button.
FLASHW_TRAY = 2,
//Flash both the window caption and taskbar button.
//This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
FLASHW_ALL = 3,
//Flash continuously, until the FLASHW_STOP flag is set.
FLASHW_TIMER = 4,
//Flash continuously until the window comes to the foreground.
FLASHW_TIMERNOFG = 12
};
bool IsFormAcive(Form f)
{
bool Status = false;
//* Check if Form is already open, if so then bring it to the front
//* If you are using a MDI parent form, include a check to see if the form is an ActiveMdiChild
// if ((f != null) && (f != MainForm.ActiveMdiChild))
if ((f != null))
{
f.Activate();
Status = true;
}
return Status;
}
/// <summary>
/// Flashes a window
/// </summary>
/// <param name="hWnd">The handle to the window to flash</param>
/// <returns>whether or not the window needed flashing</returns>
public static bool FlashWindowEx(IntPtr hWnd, dwFlags dwFlag, UInt32 uCount, UInt32 dwTimeout)
{
FLASHWINFO fInfo = new FLASHWINFO();
fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
fInfo.hwnd = hWnd;
fInfo.dwFlags = Convert.ToUInt32(dwFlag);
fInfo.uCount = uCount;
fInfo.dwTimeout = dwTimeout;
return FlashWindowEx(ref fInfo);
}
}
}
CodeKeep C# Feed Agosto 6th, 2008
Description: TreeView Style
Link:
http://www.codekeep.net/snippets/702cf2c6-20ff-48ba-9afc-1b0403772389.aspx <Style x:Key="{x:Type TreeView}" TargetType="TreeView">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="Background" Value="{StaticResource brushControlBackground}" />
<Setter Property="BorderBrush" Value="{StaticResource brushControlBorder}" />
<Setter Property="BorderThickness" Value="2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeView">
<Border
Name="Border"
CornerRadius="2"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
>
<ScrollViewer
Focusable="False"
CanContentScroll="False"
Padding="4">
<ItemsPresenter/>
</ScrollViewer>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Border" Property="Background"
Value="{StaticResource brushDisabledControlBackground}" />
<Setter TargetName="Border" Property="BorderBrush"
Value="{StaticResource brushDisabledControlBorder}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
CodeKeep C# Feed Agosto 6th, 2008
Description: How to use the DeepZoom feature of Silverlight and the MultiScaleImage control to create an image that can be panned and zoomed.
Link:
http://www.codekeep.net/snippets/925183ad-576f-413a-ace9-9551fe8d2652.aspx<UserControl x:Class="SilverlightPanoramaApplication.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="760" Height="600">
<Grid x:Name="LayoutRoot" Background="White">
<MultiScaleImage x:Name="PanoramaMultiScaleImage" Source="/HawaiiPanorama/dzc_output.xml"
Width="600" Height="600"
MouseMove="PanoramaMultiScaleImage_MouseMove"
MouseLeftButtonDown="PanoramaMultiScaleImage_MouseLeftButtonDown"
MouseLeftButtonUp="PanoramaMultiScaleImage_MouseLeftButtonUp"
MouseLeave="PanoramaMultiScaleImage_MouseLeave">
</MultiScaleImage>
<RepeatButton x:Name="ZoomIn" Width="80" Height="30" HorizontalAlignment="Left"
Content="Zoom In" Click="ZoomIn_Click"></RepeatButton>
<RepeatButton x:Name="ZoomOut" Background="DarkCyan" Width="80" Height="30"
HorizontalAlignment="Right" Content="Zoom Out"
Click="ZoomOut_Click"></RepeatButton>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightPanoramaApplication
{
public partial class Page : UserControl
{
Point lastMousePosition = new Point();
Point dragOffset;
Point currentPosition;
bool dragInProgress = false;
public Page()
{
InitializeComponent();
new MouseWheelHelper(PanoramaMultiScaleImage).Moved += delegate(object sender,
MouseWheelEventArgs e)
{
double zoomFactor = 1;
e.Handled = true;
if (e.Delta > 0)
zoomFactor = 1.1;
else
zoomFactor = 0.9;
Point p = PanoramaMultiScaleImage.ElementToLogicalPoint(lastMousePosition);
PanoramaMultiScaleImage.ZoomAboutLogicalPoint(zoomFactor, p.X, p.Y);
};
}
private void ZoomIn_Click(object sender, RoutedEventArgs e)
{
//Zoom about the centre of the image
Point p = PanoramaMultiScaleImage.ElementToLogicalPoint(new Point(
PanoramaMultiScaleImage.Width / 2, (PanoramaMultiScaleImage.Width /
PanoramaMultiScaleImage.AspectRatio) / 2));
PanoramaMultiScaleImage.ZoomAboutLogicalPoint(1.1, p.X, p.Y);
}
private void ZoomOut_Click(object sender, RoutedEventArgs e)
{
//Zoom about the centre of the image
Point p = PanoramaMultiScaleImage.ElementToLogicalPoint(new Point(
PanoramaMultiScaleImage.Width / 2, (PanoramaMultiScaleImage.Width /
PanoramaMultiScaleImage.AspectRatio) / 2));
PanoramaMultiScaleImage.ZoomAboutLogicalPoint(0.9, p.X, p.Y);
}
private void PanoramaMultiScaleImage_MouseMove(object sender, MouseEventArgs e)
{
//Capture mouse position to use as zoom centre with mouse wheel
lastMousePosition = e.GetPosition(PanoramaMultiScaleImage);
//Pan the image
if (dragInProgress)
{
Point newOrigin = new Point();
newOrigin.X = currentPosition.X - (((e.GetPosition(
PanoramaMultiScaleImage).X - dragOffset.X) /
PanoramaMultiScaleImage.ActualWidth) *
PanoramaMultiScaleImage.ViewportWidth);
newOrigin.Y = currentPosition.Y - (((e.GetPosition(
PanoramaMultiScaleImage).Y - dragOffset.Y) /
PanoramaMultiScaleImage.ActualHeight) *
PanoramaMultiScaleImage.ViewportWidth);
PanoramaMultiScaleImage.ViewportOrigin = newOrigin;
}
}
private void PanoramaMultiScaleImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
dragInProgress = true;
dragOffset = e.GetPosition(PanoramaMultiScaleImage);
currentPosition = PanoramaMultiScaleImage.ViewportOrigin;
}
private void PanoramaMultiScaleImage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
dragInProgress = false;
}
private void PanoramaMultiScaleImage_MouseLeave(object sender, MouseEventArgs e)
{
dragInProgress = false;
}
}
}