Files
PowerToys/src/modules/MouseWithoutBorders/App/Control/Machine.cs
Jeremy Sinclair 00ee6c1510 [Dev][Build] .NET 9 Upgrade (#35716)
* [Deps] Upgrade Framework Libraries to .NET 9 RC2

* [Common][Build] Update TFM to NET9

* [FileLocksmith][Build] Update TFM to NET9 in Publish Profile

* [PreviewPane][Build] Update TFM to NET9 in Publish Profile

* [PTRun][Build] Update TFM to NET9 in Publish Profile

* [Settings][Build] Update TFM to NET9 in Publish Profile

* [MouseWithoutBorders][Analyzers] Resolve WFO1000 by configuring Designer Serialization Visibility

* [Deps] Update Microsoft.CodeAnalysis.NetAnalyzers

* [Analyzers] Set CA1859,CA2263,CA2022 to be excluded from error

* [MouseWithoutBorders] Use System.Threading.Lock to lock instead of object instance

* [ColorPicker] Use System.Threading.Lock to lock instead of object instance

* [AdvancedPaste] Use System.Threading.Lock to lock instead of object instance

* [TextExtractor] Use System.Threading.Lock to lock instead of object instance

* [Hosts] Use System.Threading.Lock to lock instead of object instance

* [MouseJump] Use System.Threading.Lock to lock instead of object instance

* [PTRun] Use System.Threading.Lock to lock instead of object instance

* [Wox] Use System.Threading.Lock to lock instead of object instance

* [Peek] Use System.Threading.Lock to lock instead of object instance

* [PowerAccent] Use System.Threading.Lock to lock instead of object instance

* [Settings] Use System.Threading.Lock to lock instead of object instance

* [Deps] Update NOTICE.md

* [CI] Update .NET version step to target 9.0

* [Build] Attempt to add manual trigger for using Visual Studio Preview for building

* [Build] Fix variable typo

* [Build][Temporary] set to use preview builds

* [Build] Add missing parameters

* [Build][Temporary] directly hardcode preview image

* [Build][Temporary] Trying ImageOverride

* [Build] Revert hardcode and use ImageOverride

* [Build] Add env var for adding prerelease argument for vswhere

* [Build] Update VCToolsVersion script to use env var to optionally add prerelease version checking

* [Build] Remove unneeded parameter

* [Build] Re-add parameter in all the right places

* [CI][Build] Add NoWarn NU5104 when building with VS Preview

* [Deps] Update to stable .NET 9 packages

* [Deps] Update NOTICE.md

* Everything is WPF and WindowsForms now to fix .NET 9 dependency conflicts

* Ensure .NET 9 SDK for tests too

---------

Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
2024-11-13 12:36:45 -05:00

216 lines
6.0 KiB
C#

// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel;
using System.Windows.Forms;
// <summary>
// User control, used in the Matrix form.
// </summary>
// <history>
// 2008 created by Truong Do (ductdo).
// 2009-... modified by Truong Do (TruongDo).
// 2023- Included in PowerToys.
// </history>
using MouseWithoutBorders.Class;
using MouseWithoutBorders.Properties;
namespace MouseWithoutBorders
{
internal partial class Machine : UserControl
{
// private int ip;
// private Point mouseDownPos;
private SocketStatus statusClient;
private SocketStatus statusServer;
private bool localhost;
internal Machine()
{
InitializeComponent();
Visible = false;
MachineEnabled = false;
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
internal string MachineName
{
get => textBoxName.Text;
set => textBoxName.Text = value;
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
internal bool MachineEnabled
{
get => checkBoxEnabled.Checked;
set
{
checkBoxEnabled.Checked = value;
Editable = value;
pictureBoxLogo.Image = value ? Images.MachineEnabled : (System.Drawing.Image)Images.MachineDisabled;
OnEnabledChanged(EventArgs.Empty); // Borrow this event since we do not use it for any other purpose:) (we can create one but l...:))
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
internal bool Editable
{
set => textBoxName.Enabled = value;
// get { return textBoxName.Enabled; }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
internal bool CheckAble
{
set
{
if (!value)
{
checkBoxEnabled.Checked = true;
Editable = false;
}
checkBoxEnabled.Enabled = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
internal bool LocalHost
{
// get { return localhost; }
set
{
localhost = value;
if (localhost)
{
labelStatusClient.Text = "local machine";
labelStatusServer.Text = "...";
CheckAble = false;
}
else
{
labelStatusClient.Text = "...";
labelStatusServer.Text = "...";
CheckAble = true;
}
}
}
private void PictureBoxLogo_MouseDown(object sender, MouseEventArgs e)
{
// mouseDownPos = e.Location;
OnMouseDown(e);
}
/*
internal Point MouseDownPos
{
get { return mouseDownPos; }
}
*/
private void CheckBoxEnabled_CheckedChanged(object sender, EventArgs e)
{
MachineEnabled = checkBoxEnabled.Checked;
}
private static string StatusString(SocketStatus status)
{
string rv = string.Empty;
switch (status)
{
case SocketStatus.Resolving:
rv = "Resolving";
break;
case SocketStatus.Connected:
rv = "Connected";
break;
case SocketStatus.Connecting:
rv = "Connecting";
break;
case SocketStatus.Error:
rv = "Error";
break;
case SocketStatus.ForceClosed:
rv = "Closed";
break;
case SocketStatus.Handshaking:
rv = "Handshaking";
break;
case SocketStatus.SendError:
rv = "Send error";
break;
case SocketStatus.InvalidKey:
rv = "KeysNotMatched";
break;
case SocketStatus.Timeout:
rv = "Timed out";
break;
case SocketStatus.NA:
rv = "...";
break;
default:
break;
}
return rv;
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
internal SocketStatus StatusClient
{
get => statusClient;
set
{
statusClient = value;
if (statusClient is SocketStatus.Connected or
SocketStatus.Handshaking)
{
Editable = false;
}
labelStatusClient.Text = StatusString(statusClient) + " -->";
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
internal SocketStatus StatusServer
{
get => statusServer;
set
{
statusServer = value;
if (statusServer is SocketStatus.Connected or
SocketStatus.Handshaking)
{
Editable = false;
}
labelStatusServer.Text = StatusString(statusServer) + " <--";
}
}
private void PictureBoxLogo_Paint(object sender, PaintEventArgs e)
{
// e.Graphics.DrawString("(Draggable)", this.Font, Brushes.WhiteSmoke, 20, 15);
}
}
}