Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
220 changes: 186 additions & 34 deletions dotnet/DesktopAgent/About.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,219 @@ internal class About : Form
{
public About()
{
this.Text = Resources.lblAbout;
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.StartPosition = FormStartPosition.CenterScreen;
this.MaximizeBox = this.MinimizeBox = false;
this.Icon = Resources.AppIcon;
this.ShowInTaskbar = false;
this.AutoSize = true;
this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
this.MinimumSize = new Size(260, 100);

using MemoryStream ms = new MemoryStream(Resources.devolutions_agent_icon_shadow);

PictureBox pbLogo = new PictureBox()
Text = Resources.lblAbout;
FormBorderStyle = FormBorderStyle.FixedDialog;
StartPosition = FormStartPosition.CenterScreen;
MaximizeBox = MinimizeBox = false;
Icon = ImageResources.AppIcon;
ShowInTaskbar = false;

AutoScaleMode = AutoScaleMode.Dpi;
AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink;

MinimumSize = new Size(320, 180);
Padding = new Padding(12);

DpiAwareImageBox pbLogo = new DpiAwareImageBox
{
Image = Image.FromStream(ms),
SizeMode = PictureBoxSizeMode.Zoom,
Dock = DockStyle.Top,
Image = ImageResources.devolutions_agent_icon_shadow,
Dock = DockStyle.Fill,
MinimumSize = new Size(0, 96),
};

Label lblName = new Label()
Label lblName = new Label
{
Text = Resources.lblProductName,
Dock = DockStyle.Top,
Height = 40,
Text = StaticResources.DevolutionsAgent,
AutoSize = true,
TextAlign = ContentAlignment.MiddleCenter,
Font = new Font(Font.FontFamily, 12, FontStyle.Bold),
Dock = DockStyle.Fill,
Margin = new Padding(0, 0, 0, 6),
Font = new Font(Font.FontFamily, 12f, FontStyle.Bold),
};

Version version = Assembly.GetExecutingAssembly().GetName().Version;

Label lblVersion = new Label
{
Text = $@"{version.Major}.{version.Minor}.{version.Build}.{version.Revision}",
Dock = DockStyle.Top,
Height = 30,
AutoSize = true,
TextAlign = ContentAlignment.MiddleCenter,
Dock = DockStyle.Fill,
Margin = new Padding(0, 0, 0, 6),
};

Label lblVendor = new Label
{
Text = Resources.lblVendor,
Dock = DockStyle.Top,
Text = StaticResources.DevolutionsInc,
AutoSize = true,
TextAlign = ContentAlignment.MiddleCenter,
Font = new Font(Font.FontFamily, 7, FontStyle.Regular),
Dock = DockStyle.Fill,
Margin = new Padding(0, 0, 0, 2),
Font = new Font(Font.FontFamily, 8f, FontStyle.Regular),
};

Label lblCopyright = new Label
{
Text = $@"{Resources.lblCopyright} © 2006 - {DateTime.Now.Year}",
Dock = DockStyle.Top,
AutoSize = true,
TextAlign = ContentAlignment.MiddleCenter,
Font = new Font(Font.FontFamily, 7, FontStyle.Regular),
Dock = DockStyle.Fill,
Margin = new Padding(0, 0, 0, 0),
Font = new Font(Font.FontFamily, 8f, FontStyle.Regular),
};

this.Controls.Add(lblCopyright);
this.Controls.Add(lblVendor);
this.Controls.Add(lblVersion);
this.Controls.Add(lblName);
this.Controls.Add(pbLogo);
TableLayoutPanel layout = new TableLayoutPanel
{
Dock = DockStyle.Fill,
AutoSize = true,
AutoSizeMode = AutoSizeMode.GrowAndShrink,
ColumnCount = 1,
RowCount = 5,
Padding = new Padding(0),
Margin = new Padding(0),
};

layout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100f));

layout.Controls.Add(pbLogo, 0, 0);
layout.Controls.Add(lblName, 0, 1);
layout.Controls.Add(lblVersion, 0, 2);
layout.Controls.Add(lblVendor, 0, 3);
layout.Controls.Add(lblCopyright, 0, 4);

Controls.Add(layout);

FormClosed += (_, _) => DialogResult = DialogResult.OK;
}

protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);

if (Utils.Theme() == Utils.ThemeMode.Dark)
{
Utils.UseImmersiveDarkMode(Handle, true);
DarkTheme.Apply(this);
}
}
}

internal static class DarkTheme
{
public static readonly Color WindowBack = Color.FromArgb(32, 32, 32);

public static readonly Color PanelBack = Color.FromArgb(32, 32, 32);

public static readonly Color Text = Color.FromArgb(240, 240, 240);

public static void Apply(Control root)
{
root.BackColor = WindowBack;
root.ForeColor = Text;

ApplyToChildren(root);
}

private static void ApplyToChildren(Control parent)
{
foreach (Control c in parent.Controls)
{
switch (c)
{
case LinkLabel link:
link.LinkColor = Text;
link.ActiveLinkColor = Text;
link.VisitedLinkColor = Text;
link.BackColor = Color.Transparent;
break;

case Label lbl:
lbl.BackColor = Color.Transparent;
break;

case TableLayoutPanel tlp:
tlp.BackColor = PanelBack;
break;

case Panel p:
p.BackColor = PanelBack;
break;

case Button btn:
btn.FlatStyle = FlatStyle.Flat;
btn.BackColor = Color.FromArgb(45, 45, 45);
btn.ForeColor = Text;
btn.FlatAppearance.BorderColor = Color.FromArgb(80, 80, 80);
btn.FlatAppearance.MouseOverBackColor = Color.FromArgb(55, 55, 55);
btn.FlatAppearance.MouseDownBackColor = Color.FromArgb(65, 65, 65);
break;

default:
c.BackColor = parent.BackColor;
c.ForeColor = parent.ForeColor;
break;
}

if (c.HasChildren)
{
ApplyToChildren(c);
}
}
}
}

internal sealed class DpiAwareImageBox : Control
{
private Image image;

public Image Image
{
get => image;
set
{
image = value;
Invalidate();
}
}

public DpiAwareImageBox()
{
DoubleBuffered = true;
SetStyle(ControlStyles.ResizeRedraw, true);
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

if (image == null)
return;

e.Graphics.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighQuality;
e.Graphics.PixelOffsetMode =
System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

Rectangle dest = GetScaledRect(ClientRectangle, image.Size);
e.Graphics.DrawImage(image, dest);
}

private static Rectangle GetScaledRect(Rectangle bounds, Size imageSize)
{
float ratio = Math.Min(
(float)bounds.Width / imageSize.Width,
(float)bounds.Height / imageSize.Height);

int w = (int)(imageSize.Width * ratio);
int h = (int)(imageSize.Height * ratio);

int x = bounds.X + (bounds.Width - w) / 2;
int y = bounds.Y + (bounds.Height - h) / 2;

this.FormClosed += (_, _) => this.DialogResult = DialogResult.OK;
return new Rectangle(x, y, w, h);
}
}
}
4 changes: 4 additions & 0 deletions dotnet/DesktopAgent/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<System.Windows.Forms.ApplicationConfigurationSection>
<add key="DpiAwareness" value="PerMonitorV2" />
<add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
</System.Windows.Forms.ApplicationConfigurationSection>
</configuration>
20 changes: 20 additions & 0 deletions dotnet/DesktopAgent/DesktopAgent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
<PropertyGroup>
<ApplicationIcon>Resources\AppIcon.ico</ApplicationIcon>
<PlatformTarget>AnyCPU</PlatformTarget>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Runtime.Remoting" />
<Reference Include="System.ServiceProcess" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
Expand All @@ -37,16 +39,34 @@
<ProjectReference Include="..\..\crates\devolutions-pedm\openapi\dotnet-client\src\Devolutions.Pedm.Client\Devolutions.Pedm.Client.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\ImageResources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>ImageResources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\StaticResources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>StaticResources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\ImageResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ImageResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Properties\StaticResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>StaticResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>
Loading
Loading