Created
March 23, 2012 12:15
-
-
Save maximilian-krauss/2170153 to your computer and use it in GitHub Desktop.
Lunchtimestunt #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;using System.Drawing;class T { class L : Control { List<Point> dataPoints = new List<Point>(); public delegate void LeMoveHandler(object sender, Point cords); public event LeMoveHandler LeMove; public L() { SetStyle(ControlStyles.OptimizedDoubleBuffer, true); MouseMove += (o, e) => { Invalidate(); onLeMove(); }; MouseLeave += (o, e) => { Invalidate(); onLeMove(); }; Click += (o, e) => { dataPoints.Add(PointToClient(new Point(MousePosition.X, MousePosition.Y))); Invalidate(); }; } void onLeMove() { if (LeMove != null) LeMove(this, PointToClient(new Point(MousePosition.X, MousePosition.Y))); } protected override void OnPaint(PaintEventArgs e) { e.Graphics.FillRectangle(new SolidBrush(BackColor), ClientRectangle); dataPoints.ForEach(p => e.Graphics.FillRectangle(Brushes.Green, new Rectangle(new Point(p.X - (6 / 2), p.Y - (6 / 2)), new Size(6, 6)))); if (dataPoints.Count > 1) e.Graphics.DrawLines(Pens.Yellow, dataPoints.ToArray()); var mPos = PointToClient(new Point(MousePosition.X, MousePosition.Y)); using (var pLine = new Pen(Color.Red) { DashStyle = System.Drawing.Drawing2D.DashStyle.Dash }) { e.Graphics.DrawLine(pLine, new Point(0, mPos.Y), new Point(ClientRectangle.Width, mPos.Y)); e.Graphics.DrawLine(pLine, new Point(mPos.X, 0), new Point(mPos.X, ClientRectangle.Height)); } if (!ClientRectangle.Contains(mPos)) { e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(190, Color.Maroon)), ClientRectangle); TextRenderer.DrawText(e.Graphics, "Move your damn Mouse in here!", new Font(Font.FontFamily, 10), ClientRectangle, Color.White, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); } e.Graphics.DrawRectangle(SystemPens.ControlDark, new Rectangle(0, 0, ClientRectangle.Width - 1, ClientRectangle.Height - 1)); } } static void Main() { var f = new Form { Size = new Size(400, 400), Text = "LulForm", StartPosition = FormStartPosition.CenterScreen }; f.Controls.Add(new L { Dock = DockStyle.Fill, BackColor = Color.Black }); (f.Controls[0] as L).LeMove += (o, p) => { f.Text = string.Format("x:{0} y:{1}", p.X, p.Y); }; Application.Run(f); } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, it compiles :-)