c# Winform 继承窗体 无法拖动修改控件大小

问题描述:

一个窗体集成父窗体,发现无法直接拖动修改的控件,比如修改大小等

特征:

不禁使父窗体控件,就算新加一个控件也会这样:鼠标放到控件移动手方块上会出现一个“继承的控件”的tooptip,

异常正常情况

原因:

父窗体设置了WindowState属性为:System.Windows.Forms.FormWindowState.Maximized

在父窗体的designer.cs中有这么一句话:

this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

解决办法:

一、去掉这句话

二、放在窗体构造函数中,在这句话前面加上判断,如果VS处于设计模式,就返回

public frmBaseChild()
        {
            InitializeComponent();
            if (CheckDesingModel.IsDesingMode) return;//如果处于设计模式,返回
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        }

 

CheckDesingModel类:

internal class CheckDesingModel
{
public static bool IsDesingMode
{
get
{
bool ReturnFlag = false;
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
ReturnFlag = true;
else if (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")
ReturnFlag = true;
//if (ReturnFlag)
// Msg.Warning("设计模式");
//else Msg.Warning("非设计模式!");
return ReturnFlag;
}
}
}

原文链接:http://www.cnblogs.com/GarsonZhang/p/5078218.html

posted @ 2019-07-11 09:57  冰封一夏  阅读(2886)  评论(0编辑  收藏  举报
HZHControls控件库官网:https://www.hzhcontrols.cn