Merge pull request #2946 from mRemoteNG/copilot/add-margin-to-connection-frame

Fix connection frame color visibility by adding padding to prevent content overlap
This commit is contained in:
Dimitrij
2025-10-19 00:36:04 +01:00
committed by GitHub
5 changed files with 45 additions and 16 deletions

View File

@@ -35,6 +35,9 @@ namespace mRemoteNG.Connection
// Enable custom painting for border
this.Paint += InterfaceControl_Paint;
// Set padding to prevent content from covering the frame border
UpdatePaddingForFrameColor();
}
catch (Exception ex)
{
@@ -66,6 +69,22 @@ namespace mRemoteNG.Connection
}
}
private void UpdatePaddingForFrameColor()
{
// Add padding to prevent content from covering the frame border
if (Info?.ConnectionFrameColor != null && Info.ConnectionFrameColor != ConnectionFrameColor.None)
{
int borderWidth = 4; // Must match the border width in InterfaceControl_Paint
// Add 2px margin so the border is fully visible and not covered by child controls
int padding = borderWidth / 2 + 2;
this.Padding = new Padding(padding);
}
else
{
this.Padding = new Padding(0);
}
}
private Color GetFrameColor(ConnectionFrameColor frameColor)
{
return frameColor switch

View File

@@ -139,10 +139,13 @@ namespace mRemoteNG.Connection.Protocol
try
{
if (InterfaceControl.Size == Size.Empty) return;
NativeMethods.MoveWindow(_handle, -SystemInformation.FrameBorderSize.Width,
-(SystemInformation.CaptionHeight + SystemInformation.FrameBorderSize.Height),
InterfaceControl.Width + SystemInformation.FrameBorderSize.Width * 2,
InterfaceControl.Height + SystemInformation.CaptionHeight +
// Use ClientRectangle to account for padding (for connection frame color)
Rectangle clientRect = InterfaceControl.ClientRectangle;
NativeMethods.MoveWindow(_handle,
clientRect.X - SystemInformation.FrameBorderSize.Width,
clientRect.Y - (SystemInformation.CaptionHeight + SystemInformation.FrameBorderSize.Height),
clientRect.Width + SystemInformation.FrameBorderSize.Width * 2,
clientRect.Height + SystemInformation.CaptionHeight +
SystemInformation.FrameBorderSize.Height * 2, true);
}
catch (Exception ex)

View File

@@ -229,10 +229,13 @@ namespace mRemoteNG.Connection.Protocol.PowerShell
try
{
if (InterfaceControl.Size == Size.Empty) return;
NativeMethods.MoveWindow(_handle, -SystemInformation.FrameBorderSize.Width,
-(SystemInformation.CaptionHeight + SystemInformation.FrameBorderSize.Height),
InterfaceControl.Width + SystemInformation.FrameBorderSize.Width * 2,
InterfaceControl.Height + SystemInformation.CaptionHeight +
// Use ClientRectangle to account for padding (for connection frame color)
Rectangle clientRect = InterfaceControl.ClientRectangle;
NativeMethods.MoveWindow(_handle,
clientRect.X - SystemInformation.FrameBorderSize.Width,
clientRect.Y - (SystemInformation.CaptionHeight + SystemInformation.FrameBorderSize.Height),
clientRect.Width + SystemInformation.FrameBorderSize.Width * 2,
clientRect.Height + SystemInformation.CaptionHeight +
SystemInformation.FrameBorderSize.Height * 2, true);
}
catch (Exception ex)

View File

@@ -116,9 +116,8 @@ namespace mRemoteNG.Connection.Protocol
Control.Name = Name;
Control.Location = _interfaceControl.Location;
Control.Size = InterfaceControl.Size;
Control.Anchor = _interfaceControl.Anchor;
// Use Dock.Fill to respect padding (e.g., for connection frame color)
Control.Dock = DockStyle.Fill;
_interfaceControl.Controls.Add(Control);
return true;

View File

@@ -338,17 +338,22 @@ namespace mRemoteNG.Connection.Protocol
if (_isPuttyNg)
{
// PuTTYNG 0.70.0.1 and later doesn't have any window borders
NativeMethods.MoveWindow(PuttyHandle, 0, 0, InterfaceControl.Width, InterfaceControl.Height, true);
// Use ClientRectangle to account for padding (for connection frame color)
Rectangle clientRect = InterfaceControl.ClientRectangle;
NativeMethods.MoveWindow(PuttyHandle, clientRect.X, clientRect.Y, clientRect.Width, clientRect.Height, true);
}
else
{
int scaledFrameBorderHeight = _display.ScaleHeight(SystemInformation.FrameBorderSize.Height);
int scaledFrameBorderWidth = _display.ScaleWidth(SystemInformation.FrameBorderSize.Width);
NativeMethods.MoveWindow(PuttyHandle, -scaledFrameBorderWidth,
-(SystemInformation.CaptionHeight + scaledFrameBorderHeight),
InterfaceControl.Width + scaledFrameBorderWidth * 2,
InterfaceControl.Height + SystemInformation.CaptionHeight +
// Use ClientRectangle to account for padding (for connection frame color)
Rectangle clientRect = InterfaceControl.ClientRectangle;
NativeMethods.MoveWindow(PuttyHandle,
clientRect.X - scaledFrameBorderWidth,
clientRect.Y - (SystemInformation.CaptionHeight + scaledFrameBorderHeight),
clientRect.Width + scaledFrameBorderWidth * 2,
clientRect.Height + SystemInformation.CaptionHeight +
scaledFrameBorderHeight * 2,
true);
}