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 ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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); } } } |
| Sponsored Links |
| |||
| i am using ruler in pixels(to show the image) |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |