IT Community - Software Programming, Web Development and Technical Support

Left Top Ruler C#.NET

This is a discussion on Left Top Ruler C#.NET within the C# Programming forums, part of the Software Development category; User Control for Ruler using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 01-25-2008, 03:29 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Left Top Ruler C#.NET

User Control for Ruler


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Test
{
public partial class Ruler : UserControl
{
private int _width;
private int _height;

public int RulerWidth
{
get { return _width; }
set { _width = value; }
}
public int RulerHeight
{
get { return _height; }
set { _height = value; }
}

public Ruler()
{
InitializeComponent();
}


private void DrawRuler(Graphics g, int formWidth, int formHeight)
{
// Border
//g.DrawRectangle(Pens.Black, 0, 0, formWidth - 1, formHeight - 1);


// Width
//g.DrawString(formWidth + " pixels", Font, Brushes.Black, 10, (formHeight / 2) - (Font.Height / 2));

// Ticks
for (int i = 0; i < formWidth; i++)
{
if (i % 2 == 0)
{
int tickHeight;
if (i % 100 == 0)
{
tickHeight = 15;
DrawTickLabel(g, i.ToString(), i, formHeight, tickHeight);
DrawTick(g, i, formHeight, tickHeight);
}
else if (i % 10 == 0)
{
tickHeight = 10;
DrawTick(g, i, formHeight, tickHeight);
}
else
{
tickHeight = 5;
}


}
}
}

private static void DrawTick(Graphics g, int xPos, int formHeight, int tickHeight)
{

// Top
g.DrawLine(Pens.White, xPos + 50, 40, xPos + 50, -tickHeight + 40);

// Left
g.DrawLine(Pens.White, 40, xPos + 50, -tickHeight + 40, xPos + 50);

}


private void DrawTickLabel(Graphics g, string text, int xPos, int formHeight, int height)
{
// Top
g.DrawString(text, Font, Brushes.White, xPos + 45, -height + 20);

// Left
g.DrawString(text, Font, Brushes.White, -height+20, xPos+45);
}

private void Ruler_Paint(object sender, PaintEventArgs e)
{
Graphics graphics = e.Graphics;
int height = Width;
int width = Height;

DrawRuler(graphics, width, height);



}


}
}
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-25-2008, 04:41 AM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Smile Re: Left Top Ruler C#.NET

May i know the units u have used in this ruler?
and
Is this ruler unit can be used as centimeters?
__________________
$enthil
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-25-2008, 04:43 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: Left Top Ruler C#.NET

i am using ruler in pixels(to show the image)
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-25-2008, 04:43 AM
it.wily it.wily is offline
D-Web Programmer
 
Join Date: Jul 2007
Posts: 89
it.wily is on a distinguished road
Smile Re: Left Top Ruler C#.NET

what is this ruler unit? cm or inch?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set the top and left of a div using JavaScript? poornima HTML, CSS and Javascript Coding Techniques 1 02-10-2008 09:25 PM
Display how many days are left until 31/12/1999. itbarota HTML, CSS and Javascript Coding Techniques 1 01-04-2008 05:56 AM
How can you display how many years, months & days are left until 31/12/1999? itbarota HTML, CSS and Javascript Coding Techniques 1 12-19-2007 05:25 AM
How do I check whether the user clicked the left or right mouse button? itbarota HTML, CSS and Javascript Coding Techniques 1 09-13-2007 02:17 AM


All times are GMT -7. The time now is 08:56 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0