(view source code of marker.cs as plain text)
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Marker{public partial class FormMain : Form
{static readonly string progver = "0.10 beta";
static bool helprequested = false;
static Color ringcolor = Color.Red;
static int ringthickness = 10;
static int rotation = 0;
static int windowheight;
static int windowwidth;
static int initialheight;
static int initialwidth;
public FormMain( )
{InitializeComponent( );
this.FormBorderStyle = FormBorderStyle.None;
this.DoubleBuffered = true;
this.SetStyle( ControlStyles.ResizeRedraw, true );
}private void DrawEllipse( )
{Application.DoEvents( );
Pen pen = new Pen( ringcolor, (float)ringthickness );
Graphics graphics = this.CreateGraphics( );
if ( rotation == 0 )
{graphics.DrawEllipse( pen, new Rectangle( ringthickness, ringthickness, windowwidth - 2 * ringthickness, windowheight - 2 * ringthickness ) );
} else { // Though the following code DOES produce a rotated ellipse, // I haven't managed to make it fit within the window yet. // Set world transform of graphics object to translate.graphics.TranslateTransform( 100.0F, 0.0F );
// Then to rotate, prepending rotation matrix.graphics.RotateTransform( (float)rotation );
this.Size = new Size( Math.Max( initialwidth, initialheight ), Math.Max( initialwidth, initialheight ) );
graphics.DrawEllipse( pen, new Rectangle( ringthickness, ringthickness, initialwidth - 2 * ringthickness, initialheight - 2 * ringthickness ) );
}pen.Dispose( );
graphics.Dispose( );
}private void FormMain_FormClosing( object sender, FormClosingEventArgs e )
{if ( helprequested )
{ShowHelp( true );
} }private void FormMain_KeyUp( object sender, KeyEventArgs e )
{if ( e.KeyCode == Keys.Escape )
{Application.Exit( );
}if ( e.KeyCode == Keys.F1 )
{ShowHelp( );
} }private void FormMain_Load( object sender, EventArgs e )
{windowwidth = this.ClientRectangle.Width;
windowheight = this.ClientRectangle.Height;
initialheight = windowheight;
initialwidth = windowwidth;
string commandline = Environment.CommandLine;
if ( commandline.Contains( "/?" ) )
{ShowHelp( true );
Application.Exit( );
}if ( commandline.ToUpper( ).Contains( "/C:" ) )
{string test = commandline.Substring( commandline.IndexOf( "/C:", StringComparison.OrdinalIgnoreCase ) + 3 );
test = test.Split( ' ' )[0];
ringcolor = Color.FromName( test );
}if ( commandline.ToUpper( ).Contains( "/H:" ) )
{string test = commandline.Substring( commandline.IndexOf( "/H:", StringComparison.OrdinalIgnoreCase ) + 3 );
test = test.Split( ' ' )[0];
if ( !int.TryParse( test, out windowheight ) )
{windowheight = this.ClientRectangle.Height;
} } /* if ( commandline.ToUpper( ).Contains( "/R:" ) ) { string test = commandline.Substring( commandline.IndexOf( "/R:", StringComparison.OrdinalIgnoreCase ) + 3 ); test = test.Split( ' ' )[0]; if ( !int.TryParse( test, out rotation ) ) { rotation = 0; } } */if ( commandline.ToUpper( ).Contains( "/T:" ) )
{string test = commandline.Substring( commandline.IndexOf( "/T:", StringComparison.OrdinalIgnoreCase ) + 3 );
test = test.Split( ' ' )[0];
if ( !int.TryParse( test, out ringthickness ) )
{ringthickness = 10;
} }if ( commandline.ToUpper( ).Contains( "/W:" ) )
{string test = commandline.Substring( commandline.IndexOf( "/W:", StringComparison.OrdinalIgnoreCase ) + 3 );
test = test.Split( ' ' )[0];
if ( !int.TryParse( test, out windowwidth ) )
{windowwidth = this.ClientRectangle.Width;
} } }private void FormMain_Resize( object sender, EventArgs e )
{windowheight = this.ClientRectangle.Height;
windowwidth = this.ClientRectangle.Width;
DrawEllipse( );
}private void FormMain_Shown( object sender, EventArgs e )
{DrawEllipse( );
}private void FormMain_SizeChanged( object sender, EventArgs e )
{windowheight = this.ClientRectangle.Height;
windowwidth = this.ClientRectangle.Width;
DrawEllipse( );
}private static int ShowHelp( bool cli = false )
{string message = string.Format( "Marker.exe, Version {0}\n", progver );
message += "Show a resizable elliptic ring with transparent background on screen\n\n";
message += "Usage: \tMarker\t[ options ]\n\n";
message += "Options:\t \t/?\t\tdisplay this help and exit\n";
message += " \t \t/C:color \tdefault Red\n";
message += " \t \t/H:height \tdefault 450\n";
//message += " \t \t/R:rotation \tdefault 0\n";message += " \t \t/T:thickness\tdefault 10\n";
message += " \t \t/W:width \tdefault 800\n\n";
message += "The ellipse can be resized bij \"grabbing\" its border at top center,\n";
message += "bottom center, middle left or middle right.\n";
message += "The ellipse can be moved by \"grabbing\" its border anywhere else.\n\n";
message += "Keys: \tPress F1 to display this help text, or Escape to exit.\n\n";
message += "Credits:\tMake transparent window resizable by\n";
message += " \tuser1306322 on StackOverflow.com:\n";
message += " \thttps://stackoverflow.com/a/32261547\n";
message += " \tMake transparent window moveable by\n";
message += " \tFreewareFire on CodeProject.com\n";
message += " \thttps://www.codeproject.com/KB/cs/csharpmovewindow.aspx\n";
message += " \tOutput to parent console by Timm:\n";
message += " \tcsharp411.com/console-output-from-winforms-application/\n\n";
message += "Written by Rob van der Woude\n";
message += "https://www.robvanderwoude.com\n";
if ( cli )
{Console.Error.WriteLine( message );
Environment.Exit( -1 );
Application.Exit( );
} else {helprequested = true;
MessageBox.Show( message, "Help for Marker.exe, \u00A0 Version " + progver );
}return -1;
} #region Make Window Moveable // Code to allow dragging the window // by FreewareFire on CodeProject.com // https://www.codeproject.com/KB/cs/csharpmovewindow.aspxpublic const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImport( "user32.dll" )]
public static extern int SendMessage( IntPtr hWnd, int Msg, int wParam, int lParam );
[DllImport( "user32.dll" )]
public static extern bool ReleaseCapture( );
private void FormMain_MouseDown( object sender, MouseEventArgs e )
{if ( e.Button == MouseButtons.Left )
{ReleaseCapture( );
SendMessage( Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0 );
} } #endregion Make Window Moveable #region Make Window Resizable // Code to make borderless window resizable // by user1306322 on StackOverflow.com // https://stackoverflow.com/a/32261547private const int
HTLEFT = 10,
HTRIGHT = 11,
HTTOP = 12,
HTTOPLEFT = 13,
HTTOPRIGHT = 14,
HTBOTTOM = 15,
HTBOTTOMLEFT = 16,
HTBOTTOMRIGHT = 17;
const int _ = 10; // you can rename this variable if you like
Rectangle Top
{ get {return new Rectangle( 0, 0, this.ClientSize.Width, _ );
} }Rectangle Left
{ get {return new Rectangle( 0, 0, _, this.ClientSize.Height );
} }Rectangle Bottom
{ get {return new Rectangle( 0, this.ClientSize.Height - _, this.ClientSize.Width, _ );
} }Rectangle Right
{ get {return new Rectangle( this.ClientSize.Width - _, 0, _, this.ClientSize.Height );
} }Rectangle TopLeft
{ get {return new Rectangle( 0, 0, _, _ );
} }Rectangle TopRight
{ get {return new Rectangle( this.ClientSize.Width - _, 0, _, _ );
} }Rectangle BottomLeft
{ get {return new Rectangle( 0, this.ClientSize.Height - _, _, _ );
} }Rectangle BottomRight
{ get {return new Rectangle( this.ClientSize.Width - _, this.ClientSize.Height - _, _, _ );
} }protected override void WndProc( ref Message message )
{base.WndProc( ref message );
if ( message.Msg == 0x84 ) // WM_NCHITTEST
{var cursor = this.PointToClient( Cursor.Position );
if ( TopLeft.Contains( cursor ) )
{message.Result = (IntPtr)HTTOPLEFT;
}else if ( TopRight.Contains( cursor ) )
{message.Result = (IntPtr)HTTOPRIGHT;
}else if ( BottomLeft.Contains( cursor ) )
{message.Result = (IntPtr)HTBOTTOMLEFT;
}else if ( BottomRight.Contains( cursor ) )
{message.Result = (IntPtr)HTBOTTOMRIGHT;
}else if ( Top.Contains( cursor ) )
{message.Result = (IntPtr)HTTOP;
}else if ( Left.Contains( cursor ) )
{message.Result = (IntPtr)HTLEFT;
}else if ( Right.Contains( cursor ) )
{message.Result = (IntPtr)HTRIGHT;
}else if ( Bottom.Contains( cursor ) )
{message.Result = (IntPtr)HTBOTTOM;
} } } #endregion Make Window Resizable }}page last modified: 2025-10-11; loaded in 0.0118 seconds