this.Region Path数据导致一个小窗口

问题描述 投票:2回答:1

所以我创建了一个简单的表单来测试使用SVG图像来绘制自定义形状的窗口。 Inspiration found here

它似乎工作正常,但无论我做什么,我的窗口大小太小,无法控制。

这样做的原因:这很酷吗? Windows需要更好的主题支持。我很闷!

我在Visual Studio中使用来自nuget.com的Svg

码:

    using Svg;

    public const int WM_NCLBUTTONDOWN = 0xA1; public const int HT_CAPTION = 0x2;

    internal class NativeMethods
    {
        // Allows forms with Toolbox property set to false to be moved
        [System.Runtime.InteropServices.DllImportAttribute("user32.dll", CharSet = CharSet.Unicode)]
        internal static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
        [System.Runtime.InteropServices.DllImportAttribute("user32.dll", CharSet = CharSet.Unicode)]
        internal static extern bool ReleaseCapture();
    }
    public Form1()
    {
        InitializeComponent();
    }
    protected override void OnPaint(PaintEventArgs e)
    {
        System.Drawing.Drawing2D.GraphicsPath frmshp = new System.Drawing.Drawing2D.GraphicsPath();
        //frmshp.AddEllipse(0, 0, this.Width, this.Height);

        //SvgDocument.Open(@"TestWindowsshape.svg");
        SvgDocument newshp = SvgDocument.Open(@"TestWindowsshape.svg");
        frmshp = (newshp.Path);

        this.Region = new Region(frmshp);
    }
    private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        // Make settings window movable without a titlebar
        if (e.Button == MouseButtons.Left)
        {
            NativeMethods.ReleaseCapture();
            NativeMethods.SendMessage(Handle, WM_NCLBUTTONDOWN (IntPtr)HT_CAPTION, (IntPtr)0);
        }
    }

我试图增加svg大小,使用代码一些,但我做的任何事情都不会使绘制的窗口更大。我知道我可以使用BMP和TransparancyKey选项来做到这一点,但我不想这样做,因为BMP和透明度方法的缺点是无法在位图本身中使用一种颜色。任何意见,将不胜感激

编辑:

   Matrix m = new Matrix();
   m.Scale(100, 100, MatrixOrder.Append);
   m.Translate(100, 100, MatrixOrder.Append);
   newshp.Path.Transform(m);

已经尝试过,没有效果。我认为这应该有效,这是否意味着问题出在我的SVG中?

c# windows winforms svg
1个回答
1
投票

问题似乎是在SVG文件中,我在Notepad ++中调整了矩形的大小并获得了更大的窗口,但更复杂的形状将是一件麻烦事。似乎Inkscape无法创建可靠大小的SVG ...我将“文档属性”设置为我的屏幕分辨率,但向量都变得太小。也许Illustrator可以正确地做到这一点。

© www.soinside.com 2019 - 2024. All rights reserved.