添加项目文件。
This commit is contained in:
17
ShrlAlgo.MsAddIns/Views/CustomToolSettings.xaml
Normal file
17
ShrlAlgo.MsAddIns/Views/CustomToolSettings.xaml
Normal file
@@ -0,0 +1,17 @@
|
||||
<wpf:ToolSettingsHost
|
||||
x:Class="ShrlAlgo.MsAddins.Views.CustomToolSettings"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:wpf="clr-namespace:Bentley.MstnPlatformNET.WPF;assembly=Bentley.MicroStation.WPF"
|
||||
Width="300"
|
||||
Height="300"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<Button
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Content="点击" />
|
||||
</Grid>
|
||||
</wpf:ToolSettingsHost>
|
||||
65
ShrlAlgo.MsAddIns/Views/CustomToolSettings.xaml.cs
Normal file
65
ShrlAlgo.MsAddIns/Views/CustomToolSettings.xaml.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using Bentley.ResourceManagement;
|
||||
|
||||
namespace ShrlAlgo.MsAddins.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// CustomTool.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class CustomToolSettings : Bentley.MstnPlatformNET.WPF.ToolSettingsHost
|
||||
{
|
||||
public CustomToolSettings()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
[DllImport("stdmdlbltin.dll", SetLastError = true)]
|
||||
public static extern int mdlNativeWindow_getToolSettingsWindow(out IntPtr windowPp);
|
||||
|
||||
|
||||
[DllImport("nativewindow.dll", SetLastError = true)]
|
||||
public static extern int mdlNativeWindow_setSize(IntPtr windowP, int width, int height);
|
||||
public override void Attach(IMatchLifetime addIn)
|
||||
{
|
||||
base.Attach(addIn);
|
||||
|
||||
// ElementHost.Width = (int)RenderSize.Width;
|
||||
// ElementHost.Height = (int)RenderSize.Height;
|
||||
mdlNativeWindow_getToolSettingsWindow(out IntPtr windowPp);
|
||||
mdlNativeWindow_setSize(windowPp, ElementHost.Width, ElementHost.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据缩放比重新调整控件大小
|
||||
/// </summary>
|
||||
public new void AdjustWidthAndHeight()
|
||||
{
|
||||
double dipScale = GetDipScale();
|
||||
Width *= dipScale;
|
||||
Height *= dipScale;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取显示器缩放比
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public double GetDipScale()
|
||||
{
|
||||
Graphics g = Graphics.FromHwnd(IntPtr.Zero);
|
||||
double dipScale = 1;
|
||||
switch (g.DpiX)
|
||||
{
|
||||
case 96: dipScale = 1; break;
|
||||
case 120: dipScale = 1.25; break;
|
||||
case 144: dipScale = 1.5; break;
|
||||
case 168: dipScale = 1.75; break;
|
||||
case 192: dipScale = 2; break;
|
||||
}
|
||||
|
||||
return dipScale;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user