Here is a cool 'custom panel' I've found that might be very handy...
The Joy Of Programming: A Simple Radial Panel for WPF and SilverLight
Usage examples
Nicer selection menu, Clock digits, dynamic elements in radial presentation rather than list...
Example outputs
source - http://www.codeproject.com/KB/WPF/SpiderControl.aspx
Thursday, December 8, 2011
WPF: Bulletdecorator XAML example
BulletDecorator is basically like any editor bullet (like MS word's bullet). You can specify how to draw the bullet itself and decorate what ever you need.
Suppose we want to do the following effect in WPF:
And here is the results:
Source - Bulletdecorator in WPF | Controls | w3mentor
Suppose we want to do the following effect in WPF:
- This is a bullet
Here is the source for it:
Code Snippet
- <BulletDecorator>
- <BulletDecorator.Bullet>
- <Polygon Margin=" 2, 0, 0, 0" Points="0, 5 5, 0 10, 5 5, 10" Fill=" Blue" />
- </BulletDecorator.Bullet>
- <TextBlock Margin="10, 0, 0, 0" Text="This is a bullet" />
- </BulletDecorator>
And here is the results:
Source - Bulletdecorator in WPF | Controls | w3mentor
Wednesday, December 7, 2011
TUTORIAL: VS - Creating Code Snippets - CodeProject
I was in the middle of creating my experiance/article about the snippets subject when I got an email from http://www.codeproject.com/ with this wonderful article.
I've already created some snippets, feel free to use them:
'Decorator-Pattern' snippet (activation: dp_decorator + TAB):
Code Snippet
- xml version="1.0" encoding="utf-8" ?>
- <CodeSnippetsxmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
- <CodeSnippet Format="1.0.0">
- <Header>
- <Title>Decorator DPTitle>
- <Shortcut>dp_decoratorShortcut>
- <Description>Code snippet for decorator design patternDescription>
- <Author>S.OAuthor>
- <SnippetTypes>
- <SnippetType>ExpansionSnippetType>
- SnippetTypes>
- Header>
- <Snippet>
- <Declarations>
- <Literal>
- <ID>ComponentID>
- <ToolTip>Component nameToolTip>
- <Default>ComponentDefault>
- Literal>
- <Literal>
- <ID>DecoratorID>
- <ToolTip>Decorator nameToolTip>
- <Default>DecoratorDefault>
- Literal>
- Declarations>
- <Code Language="csharp">
- // Decorator patern:
- // http://en.wikipedia.org/wiki/Decorator_pattern#Structure
- // http://www.dofactory.com/Patterns/PatternDecorator.aspx
- abstract class $Component$
- {
- public abstract void Operation();
- }
- abstract class $Decorator$ : $Component$
- {
- protected $Component$ _$Component$;
- public void SetComponent($Component$ component)
- {
- this._$Component$ = component;
- }
- public override void Operation()
- {
- if (_$Component$ != null)
- {
- _$Component$.Operation();
- // + [your operation here]
- }
- }
- }
- $end$
- ]]>
- Code>
- Snippet>
- CodeSnippet>
- CodeSnippets>
The 'Event changed property' snippet (eprop + TAB):
Code Snippet
- xml version="1.0" encoding="utf-8" ?>
- <CodeSnippetsxmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
- <CodeSnippet Format="1.0.0">
- <Header>
- <Title>event changed propertyTitle>
- <Shortcut>epropShortcut>
- <Description>Code snippet for eprop...Description>
- <Author>SOAuthor>
- <SnippetTypes>
- <SnippetType>ExpansionSnippetType>
- SnippetTypes>
- Header>
- <Snippet>
- <Declarations>
- <Literal Editable="true">
- <ID>prop_nameID>
- <ToolTip>property nameToolTip>
- <Function>PropName()Function>
- <Default>PropNameDefault>
- Literal>
- <Literal Editable="true">
- <ID>prop_typeID>
- <ToolTip>property typeToolTip>
- <Function>PropType()Function>
- <Default>ObjectDefault>
- Literal>
- Declarations>
- <Code Language="csharp">
- #region $prop_name$
- ///
- /// Occurs when $prop_name$ changes.
- ///
- public event EventHandler $prop_name$Changed;
- ///
- /// Raises the
event. - ///
- /// The
instance containing the event data. - protected virtual void On$prop_name$Changed(EventArgs e)
- {
- if ($prop_name$Changed != null)
- $prop_name$Changed(this, e);
- }
- private $prop_type$ _$prop_name$ = null;$end$
- ///
- /// Gets or sets the type of the region.
- ///
- ///
- /// The type of the region.
- ///
- public $prop_type$ $prop_name$
- {
- get { return _$prop_name$; }
- set
- {
- if (_$prop_name$ != value)
- {
- _$prop_name$ = value;
- On$prop_name$Changed(new EventArgs());
- }
- }
- }
- #endregion
- ]]>
- Code>
- Snippet>
- CodeSnippet>
- CodeSnippets>
And the 'TODO' snippet (TD + TAB), need some polish like auto date/time stamp, priority...:
Code Snippet
- xml version="1.0" encoding="utf-8" ?>
- <CodeSnippetsxmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
- <CodeSnippet Format="1.0.0">
- <Header>
- <Title>TODOTitle>
- <Shortcut>TDShortcut>
- <Description>Code snippet for TODO...Description>
- <Author>SOAuthor>
- <SnippetTypes>
- <SnippetType>ExpansionSnippetType>
- SnippetTypes>
- Header>
- <Snippet>
- <Declarations>
- Declarations>
- <Code Language="csharp">// TODO:P, TimeStamp, S.O: $end$]]>
- Code>
- Snippet>
- CodeSnippet>
- CodeSnippets>
My advice: if you already created a code pattern twice (meaning - you copied and pasted a code and renamed some variables and function/property names), add it to your snippets, you'll need it and it will save time.
REMARK: Please follow the codeproject artical if you wish to install/use them...
REMARK: Please follow the codeproject artical if you wish to install/use them...
Labels:
Best practices,
C#,
Code,
examples,
plugin,
Productivity,
Snippets,
Tips,
Tutorial,
Tweaks,
Visual Studio - IDE
Tuesday, December 6, 2011
TIP: Creating a file, fast, with incremental values (using FOR /L).
I needed to create a file (called urls.txt) that contains lots of image urls, here is the solution:
REM ~~~~~ gget.bat file content ~~~~~~~~~~~~~~~
@echo off
for /L %%a in (0,1,1984) do (
echo http://domain.com/images/%%a.jpg >>c:\urls.txt
)
ECHO DONE!
pause
- Create a batch file (I'll call it gget.bat).
- copy and paste the following to gget.bat file.
REM ~~~~~ gget.bat file content ~~~~~~~~~~~~~~~
@echo off
for /L %%a in (0,1,1984) do (
echo http://domain.com/images/%%a.jpg >>c:\urls.txt
)
ECHO DONE!
pause
REM ~~~~~ gget.bat file content ~~~~~~~~~~~~~~~
- change the numbers in "(0,1,1984)" to the desired ones (please read more about 'FOR /L' here.).
the result is a file 'c:\urls.txt' that contains this:
http://domain.com/images//0.jpg
http://domain.com/images//1.jpg
http://domain.com/images//2.jpg
http://domain.com/images//3.jpg
...
http://domain.com/images//1983.jpg
http://domain.com/images//1984.jpg
Hope it helps...
Monday, December 5, 2011
TIP - How to check an errorlevel of a program...
First understand a little about error levels... Batch files - Errorlevels:
Next... Write this code the a batch file and run it (change the runme.exe to the program that you wish to check the error-level).
#~~~~~~~~~~~~~~~~~~~~~~~~~
runme.exe
Next... Write this code the a batch file and run it (change the runme.exe to the program that you wish to check the error-level).
#~~~~~~~~~~~~~~~~~~~~~~~~~
runme.exe
ECHO.%ERRORLEVEL%
PAUSE
PAUSE
#~~~~~~~~~~~~~~~~~~~~~~~~~
Hope it helps...
Hope it helps...
Tuesday, November 15, 2011
Example: C# dynamic 'Enum' like solution.
Example usage:
Code Snippet
- using System;
- using System.Collections.Generic;
- namespace GuiLib.TeraRegion
- {
- public class TeraRegionModel
- {
- /// <summary>
- /// Dynamic enum of RegionTypes.
- /// <remarks>* This is a [Flags] and normal mixed enum!
- /// * 0 is reserved! it's not used!
- /// * 1 is reserved! it's void.
- /// Find it's max and assigne it's next value like this:
- /// var next_enum_val = RegionTypes.Values.Max<ulong>();
- /// RegionTypes.Add("new_item", next_enum_val*2);
- /// </remarks>
- /// </summary>
- public static Dictionary<string, ulong> RegionTypes = new Dictionary<string, ulong>()
- {
- {"void", 1}
- };
- #region RegionType
- /// <summary>
- /// Occurs when RegionType changes.
- /// </summary>
- public event EventHandler RegionTypeChanged;
- /// <summary>
- /// Raises the <see cref="E:RegionTypeChanged"/> event.
- /// </summary>
- /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
- protected virtual void OnRegionTypeChanged(EventArgs e)
- {
- if (RegionTypeChanged != null)
- RegionTypeChanged(this, e);
- }
- private ulong _RegionType = 1;
- /// <summary>
- /// Gets or sets the type of the region.
- /// </summary>
- /// <value>
- /// The type of the region.
- /// </value>
- public ulong RegionType
- {
- get
- {
- return _RegionType;
- }
- set
- {
- if (_RegionType != value)
- {
- _RegionType = value;
- OnRegionTypeChanged(new EventArgs());
- }
- }
- }
- #endregion
- }
- }
Monday, November 14, 2011
Tip: C# dynamic 'Enum' like solution.
Hi,
This is very usefull if you wish to be able to create dynamic enums.
Motivation
* You need to enumerate something but wish to add items to it in runtime (e.g. your server should support v1 protocol and v2 protocol where v2 protocol extends v1.enum).
* You wish to extand this enum dynamically by an outside addin.
Solution and prof
This is very usefull if you wish to be able to create dynamic enums.
Motivation
* You need to enumerate something but wish to add items to it in runtime (e.g. your server should support v1 protocol and v2 protocol where v2 protocol extends v1.enum).
* You wish to extand this enum dynamically by an outside addin.
Solution and prof
Code Snippet
- enum MyEnum : ulong
- {
- // NOTICE: string_name = ulong_value,
- first = 2<<0,
- second = 2<<1,
- last = 2<<2,
- max = 2 << 63
- // dynamic string name = dynamic ulong value!
- }
- Dictionary<string, ulong> DynamicEnum1 = new Dictionary<string, ulong>()
- {
- {"first", 2 << 0},
- {"second", 2 << 1},
- {"last", 2 << 2},
- {"max", 2 << 63}
- };
- public void usage()
- {
- MyEnum qwe = MyEnum.first;
- DynamicEnum1.Add("another_one", 2 << 3);
- UInt64 qwe2 = DynamicEnum1["first"];
- // (UInt64)qwe == qwe2!!
- }
Hope it helps.
Subscribe to:
Posts (Atom)