为什么每次我在Form1设计器上拖动控件时,用户控件的大小都会改变?

huangapple go评论134阅读模式
英文:

Why the usercontrol size is changing each time i'm dragging the control over form1 designer?

问题

在Form1设计器中拖动UserControl后,我尝试在其上更改UserControl的大小,但当我拖动UserControl时,UserControl的大小会发生变化。

以下是两个截图,显示了每次我拖动UserControl时UserControl的大小。

UserControl是地图。

当我按住鼠标在UserControl上时,它是实际大小的:

为什么每次我在Form1设计器上拖动控件时,用户控件的大小都会改变?

一旦我松开鼠标左键,不再按住它,UserControl的大小在UserControl设计器上发生了变化,我可以看到UserControl的实际大小,但大部分是空的,地图内部现在较小:

为什么每次我在Form1设计器上拖动控件时,用户控件的大小都会改变?

UserControl的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DotNetBrowser.Browser;
using DotNetBrowser.Engine;
using DotNetBrowser.WinForms;

namespace Weather
{
    public partial class GoogleMapsUserControl : UserControl
    {
        public static IBrowser browser;
        public static IEngine engine;

        public GoogleMapsUserControl()
        {
            InitializeComponent();

            engine = EngineFactory.Create(new EngineOptions.Builder
            {
                LicenseKey = "KEY HERE"
            }.Build());

            // 创建和初始化IEngine
            // engine = EngineFactory.Create();

            // 创建Windows Forms BrowserView控件
            BrowserView browserView = new BrowserView()
            {
                Dock = DockStyle.Fill
            };

            // 创建IBrowser
            browser = engine.CreateBrowser();
            browser.Navigation.LoadProgressChanged += Navigation_LoadProgressChanged;
            browser.Navigation.LoadFinished += Navigation_LoadFinished;
            browser.Navigation.LoadUrl("D:\\Csharp Projects\\Weather\\map.html");

            // 从Browser初始化Windows Forms BrowserView控件
            browserView.InitializeFrom(browser);

            this.Controls.Add(browserView);
        }

        private void Navigation_LoadProgressChanged(object sender, DotNetBrowser.Navigation.Events.LoadProgressChangedEventArgs e)
        {

        }

        private void Navigation_LoadFinished(object sender, DotNetBrowser.Navigation.Events.LoadFinishedEventArgs e)
        {

        }

        private void GoogleMapsUserControl_Load(object sender, EventArgs e)
        {

        }
    }
}
英文:

once I dragged the usercontrol to form1 designer.
then I tried to change the usercontrol size while it's on form1 designer but then when I drag the usercontrol around the usercontrol size is changing.

here are two screenshots showing the usercontrol size each time I'm dragging it.

the usercontrol is the map.

when I hold down the mouse on the usercontrol it's in its actual size:

为什么每次我在Form1设计器上拖动控件时,用户控件的大小都会改变?

once I leave the mouse left button and not holding it down the size of the usercontrol has changed on the usercontrol designer I can see the usercontrol actual size but most of is empty the map inside is now smaller:

为什么每次我在Form1设计器上拖动控件时,用户控件的大小都会改变?

the user control code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DotNetBrowser.Browser;
using DotNetBrowser.Engine;
using DotNetBrowser.WinForms;

namespace Weather
{
    public partial class GoogleMapsUserControl : UserControl
    {
        public static IBrowser browser;
        public static IEngine engine;

        public GoogleMapsUserControl()
        {
            InitializeComponent();

            engine = EngineFactory.Create(new EngineOptions.Builder
            {
                LicenseKey = "KEY HERE"
            }.Build());

            // Create and initialize the IEngine
            //engine = EngineFactory.Create();

            // Create the Windows Forms BrowserView control
            BrowserView browserView = new BrowserView()
            {
                Dock = DockStyle.Fill
            };

            // Create the IBrowser
            browser = engine.CreateBrowser();
            browser.Navigation.LoadProgressChanged += Navigation_LoadProgressChanged;
            browser.Navigation.LoadFinished += Navigation_LoadFinished;
            browser.Navigation.LoadUrl("D:\\Csharp Projects\\Weather\\map.html");

            // Initialize the Windows Forms BrowserView control
            browserView.InitializeFrom(browser);

            this.Controls.Add(browserView);

            
        }

        private void Navigation_LoadProgressChanged(object sender, DotNetBrowser.Navigation.Events.LoadProgressChangedEventArgs e)
        {
            
        }

        private void Navigation_LoadFinished(object sender, DotNetBrowser.Navigation.Events.LoadFinishedEventArgs e)
        {
            
        }

        private void GoogleMapsUserControl_Load(object sender, EventArgs e)
        {

        }
    }
}

答案1

得分: 1

我认为你已经将地图用户控件拖到了“下载”组合框内,所以地图被组合框的限制所“裁剪”。请将地图控件拖到组合框外,直接放在窗体上。

在GroupBox内放置ListView的示例:

为什么每次我在Form1设计器上拖动控件时,用户控件的大小都会改变?

英文:

I think you have dragged the map usercontrol INSIDE the GroupBox "Download", so the map is "clipped" by the groupbox limits. Drag the map control outside the groupbox, directly over the form.

Example of ListView inside GroupBox:

为什么每次我在Form1设计器上拖动控件时,用户控件的大小都会改变?

huangapple
  • 本文由 发表于 2023年3月4日 04:25:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75631588.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定