in

ASP.NET Weblogs

This Blog

Syndication

My Job

Jeff Key

It works on my machine

Ruler

Need to measure something? I did at some point and wrote this quickie (source, too). Gotta love how .NET makes writing one-off things quicker than searching for them on the web.

Published Sep 01 2004, 10:02 PM by jeffreykey
Filed under:

Comments

 

William Luu said:

Cool, I needed one a few months back, so I downloaded one called Pixel Ruler by mioplanet.

But i'll give your app a try next time :)
September 1, 2004 11:26 PM
 

William Luu said:

Ok, I just tried it, and again, cool!

But one more missing feature, being able to flip the ruler in another direction (eg: go from horizontal to vertical, and vice versa).
September 1, 2004 11:30 PM
 

Jeff Key said:

Don't get your hopes up -- I whipped this up in a pinch, so it's not exactly packed with features. ;)
September 1, 2004 11:32 PM
 

Jeff Key said:

Wow, you're quick! Good idea. I'll add that when I get some free time (which is in very short supply right now).

Thanks.
September 1, 2004 11:35 PM
 

William Luu said:

Jeff, well seeing as you have released your source code, it won't be hard for others to add new features to it.

I'm not that quick, am I? I just saw it flash up as a new post in RSS Bandit during my lunch break. :)
September 1, 2004 11:43 PM
 

Adam Kinney said:

Sweet!

(you need to add sliver.windows.forms.dll to the source code.zip file though)
September 2, 2004 12:05 AM
 

TrackBack said:

Will's Blog - Adventures of an IT Grad » Another Pixel Ruler
September 2, 2004 12:40 AM
 

Jeff Key said:

Oops -- thanks, Adam. The assembly is in the non-source download in the meantime.
September 2, 2004 7:34 AM
 

Darrell said:

I think it's only quicker for you since you actually do Windows development (I'm an ASP.NET jockey). :)
September 2, 2004 8:35 AM
 

Jeff Key said:

Are you saying you can't do that in ASP.NET?! What's all this praise I've been hearing? :)

There is a bit of a learning curve, but once you're familiar with the System.Windows.Forms namespace, it's really a matter of just banging things out -- and quickly.
September 2, 2004 9:38 AM
 

TrackBack said:

September 2, 2004 11:24 AM
 

TrackBack said:

September 2, 2004 11:27 AM
 

TrackBack said:

September 2, 2004 1:33 PM
 

Flip said:

Appologies for the formating...
<PRE>
line 26:
private bool _Flipped = false;
line 61:
_menu.MenuItems.Add(new MenuItem("-"));

mi = new MenuItem("Flip");
mi.Click += new EventHandler(MenuHandler);
_menu.MenuItems.Add(mi);

Line 215:

if (Flipped) {
// Width
e.Graphics.DrawString(Height + " pixels", Font, Brushes.Black, (Width / 2) - (Font.SizeInPoints / 2), 10);

// Ticks
for (int i = 0; i < Height; i++) {
if (i % 2 == 0) {
int width;
if (i % 100 == 0) {
width = 15;
DrawTickLabel(e.Graphics, i.ToString(), i, width);
} else if (i % 10 == 0) {
width = 10;
} else {
width = 5;
}
DrawTick(e.Graphics, i, width);
}
}
} else {
// Width
e.Graphics.DrawString(Width + " pixels", Font, Brushes.Black, 10, (Height / 2) - (Font.Height / 2));

// Ticks
for (int i = 0; i < Width; i++) {
if (i % 2 == 0) {
int height;
if (i % 100 == 0) {
height = 15;
DrawTickLabel(e.Graphics, i.ToString(), i, height);
} else if (i % 10 == 0) {
height = 10;
} else {
height = 5;
}
DrawTick(e.Graphics, i, height);
}
}
}

Line 258:
private void DrawTick(Graphics g, int xPos, int height)
{
if (Flipped) {
// Top
g.DrawLine(Pens.Black, 0, xPos, height, xPos);
// Bottom
g.DrawLine(Pens.Black, Width, xPos, Width - height, xPos);
} else {
// Top
g.DrawLine(Pens.Black, xPos, 0, xPos, height);
// Bottom
g.DrawLine(Pens.Black, xPos, Height, xPos, Height - height);
}
}

Line 273:
private void DrawTickLabel(Graphics g, string text, int xPos, int height)
{
if (Flipped) {
// Top
g.DrawString(text, Font, Brushes.Black, height, xPos);
// Bottom
g.DrawString(text, Font, Brushes.Black, Width - height - Font.SizeInPoints, xPos);
} else {
// Top
g.DrawString(text, Font, Brushes.Black, xPos, height);
// Bottom
g.DrawString(text, Font, Brushes.Black, xPos, Height - height - Font.Height);
}
}

Line 315:
case "Flip":
mi.Checked = !mi.Checked;
Flipped = mi.Checked;
this.Refresh();
break;
</PRE>
September 2, 2004 2:36 PM
 

Flip said:

uhg.

Basically, for flipping, add a property and a menu item, and change the resize method and two drawing methods.
Flip flop hieght & width, and change the DrawTick and DrawTickLabel XY from/to parameters
September 2, 2004 2:41 PM
 

TrackBack said:

September 2, 2004 6:48 PM
 

TrackBack said:

September 2, 2004 6:48 PM
 

Jeff Key said:

Thanks, Flip. I went with a couple of Graphics' transform methods instead.
September 2, 2004 8:35 PM
 

Drew Marsh said:

Awesome.

Quick suggestion, enable key board support for pixel nudging. Maybe move a configurable amount of pixels on keypress unless CTRL is held down, then move one pixel at a time.
September 2, 2004 9:51 PM
 

Jeff Key said:

Good idea, Drew. I added that plus CTRL+Shift+ArrowKey to resize.
September 2, 2004 11:44 PM
 

TrackBack said:

September 3, 2004 11:37 AM
 

Richard Hsu said:

Super cool, I am actively evangelising it now.
September 9, 2004 10:42 AM
 

Rob said:

Seems to be missin using sliver.Windows.Forms;

January 9, 2008 2:16 AM
 

asp net 100 screen height said:

Pingback from  asp net 100 screen height

April 17, 2008 9:35 PM

Leave a Comment

(required)  
(optional)
(required)  
Add