Add padding to InterfaceControl to make connection frame color visible

Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-10-18 23:18:15 +00:00
parent 045aa631e4
commit 55fec45b58
3 changed files with 31 additions and 8 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

@@ -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);
}