Skip to content

Commit

Permalink
Add a simple clock box at the screen top when maximizing and minimizi…
Browse files Browse the repository at this point in the history
…ng. Just to be able to keep in touch with reality.
  • Loading branch information
sverrirs committed Mar 28, 2016
1 parent 1db6a01 commit 85845e7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
11 changes: 10 additions & 1 deletion Examples/VideoPlayerController/VideoPlayerController/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public enum Players
/// </summary>
private Players _player;

private OnScreenPopupForm _messageBox = new OnScreenPopupForm();
private OnScreenPopupForm _messageBox = new OnScreenPopupForm() {DisplayAt = DisplayLocation.BottomLeft};

private OnScreenPopupForm _clockBox = new OnScreenPopupForm() {DisplayAt = DisplayLocation.TopRight, BackColor = Color.DarkSlateGray};

/// <summary>
/// Used to lock the <see cref="SendKeysToWindow"/> function critical section
Expand Down Expand Up @@ -96,6 +98,9 @@ protected override void Dispose(bool disposing)
_messageBox?.Dispose();
_messageBox = null;

_clockBox?.Dispose();
_clockBox = null;

_device?.Disconnect();
_device = null;
}
Expand Down Expand Up @@ -180,6 +185,10 @@ private void SendKeysToWindow(Controller controller, Buttons buttons)
if (!string.IsNullOrEmpty(keysToSend))
{
SendKeys.SendWait(keysToSend);

// Hack for fullscreen toggle
if( keysToSend == "f" )
_clockBox.ShowMessage(DateTime.Now.ToString("HH:mm"), this);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

namespace VideoPlayerController
{

public partial class OnScreenPopupForm : Form
{
private Timer _hideTimer;

public string Message { get { return lblMessage.Text; } private set { lblMessage.Text = value ?? string.Empty; } }

public DisplayLocation DisplayAt { get; set; } = DisplayLocation.BottomLeft;

public OnScreenPopupForm()
{
InitializeComponent();
Expand Down Expand Up @@ -65,22 +66,48 @@ private void lblMessage_VisibleChanged(object sender, EventArgs e)
{
if (!this.Visible)
return;

// If being shown then we want to place it in the lower bottom corner of the screen
int y = Screen.PrimaryScreen.Bounds.Bottom - this.Height;
this.Location = new Point(0, y);

var loc = Point.Empty;

switch (DisplayAt)
{
case DisplayLocation.BottomLeft:
// If being shown then we want to place it in the lower bottom corner of the screen
loc = new Point(0,
Screen.PrimaryScreen.Bounds.Bottom - this.Height);
break;
case DisplayLocation.TopRight:
loc = new Point(Screen.PrimaryScreen.Bounds.Right - this.Width,
Screen.PrimaryScreen.Bounds.Top);
break;
}

// If no location is set then don't show the form
if (loc == Point.Empty)
return;

this.Location = loc;
this.TopMost = true;

// Start timer to hide form again in 5 sec
_hideTimer.Change(5000, Timeout.Infinite);
// Start timer to hide form again in x sec
_hideTimer.Change(3000, Timeout.Infinite);
}

public void ShowMessage(string message, IWin32Window parent = null)
{
this.Message = message;

if( !this.Visible )
// Resize the form to better fit the text
this.Width = ((int) this.CreateGraphics().MeasureString(message, lblMessage.Font).Width) + 20;

if ( !this.Visible )
this.Show(parent);
}
}

public enum DisplayLocation
{
BottomLeft,
TopRight
}
}

0 comments on commit 85845e7

Please sign in to comment.