所有,
我已经完成了GUI设计阶段......现在我已经开始为我的应用程序中的所有控件添加有意义的名称.每当我点击控件改变它的名字时,Visual Studio就会让我疯狂自动生成事件(好吧所以只有当我搞砸了,双击......但仍然很烦人时).
有没有办法暂时禁用此功能?我仍然想要它,因为当我编码时它是一个很好的捷径.
谢谢!
我的问题不是如何在设计时进行调试。我实际上想通过设计器中可用的事件进行调试。我知道表单有加载和其他类型的事件。Windows 窗体设计器中是否有任何事件,例如 init、load 等?
我已经通过用户控件在 ASP 中进行了类似的调试。它允许我们在将用户控件添加到设计器之前查看其输出 HTML。
我知道 Windows 窗体和 ASP 是不同的,但是在实际呈现控件之前应该有一些事件来检查控件的值。
我的表单需要很长时间才能在 VS 设计器中打开。因此,我将调试器附加到 VisualStudio (devenv.exe),在我的 Form 的 InitializeComponent 中设置一个断点以逐步查看问题所在。但是,断点没有被击中。
我创建了一个自定义控件和组件,如下代码所示,
public class CustomComponent : Component
{
private string style;
public CustomControl Control { get; set; }
public string Style
{
get
{
return style;
}
set
{
style = value;
Control.Style = value;
}
}
}
public class CustomControl : Control
{
string style;
public string Style
{
get
{
return style;
}
set
{
style = value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
之后,我将控件添加到表单中,并将组件添加到表单中。然后尝试分配 Component.Control 值。分配值后,如果我尝试更改组件的样式属性,控件中的样式属性在设计器级别不会更改,如下图所示,
如果我单击了控件的 Style 属性,它将被更新,如下图所示,
当我尝试在我的 c# .NET Framework 4.7.2 类库中打开表单时出现此错误。检查自动生成绑定重定向
调用堆栈是
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) …Run Code Online (Sandbox Code Playgroud) 我理解与Windows窗体/控制文件分组的*.designer文件.但不确定附加的*.resx文件的相关性和用途是什么.
我可以不创建附加此文件的表单/控件吗?
I created SubCtrl inheriting UserControl. It has no code. I created then Ctrl, which also inherits UserControl. It has a SubCtrl in it and its only code means to expose it publicly so it appears in the property list of Ctrl:
public subctrl.SubCtrl SUBCTRL
{
get { return this.subCtrl1; }
}
Run Code Online (Sandbox Code Playgroud)
Then I created a simple Form project which only has a Ctrl in it and no code. As I wanted, SUBCTRL appears in the property list of Ctrl so …
我使用VS2008设计器从Windows.Form类派生了A类.当我在Visual Studio解决方案资源管理器中双击文件名时,表单设计器将打开.这是期望的行为.
我有一个第二类B,派生自A(手动).这个类是纯代码 - 它添加了一些功能,但表单是相同的 - 但如果我在Visual Studio解决方案资源管理器中双击它的文件名,它将打开表单设计器.这是不希望的行为,特别是因为我需要生成类似的派生类CZ.
有没有办法强制文件始终在代码编辑器中打开?我知道有两个建议的解决方法:
给B类属性:[System.ComponentModel.DesignerCategory("")]
根据各种帖子,这似乎在过去有效,但似乎对我的情况没有任何影响.VS环境仍尝试为该类打开表单设计器.
将源文件重命名为significname.Designer.cs
这......好吧,它不是很好,是吗?
解决方案(1)是否还能运作?如果是这样,我可能做错了什么?
还是有其他解决方案吗?
我在Microsoft Visual C#2010 Express中构建我的界面,我注意到控件的属性工具栏中没有"set parent"属性?
我想知道为什么会这样,如果有一个干净的方式来启用此功能.或者如果没有,为什么它不可用?
我需要它的一个例子是,当我使用Splitcontainer并且Panel1有10个子面板都使用Dock模式'FIll'时,将新面板添加到Spitcontainer面板1变得非常困难.Visual Studio总是假设我正试图将我的新面板作为已经存在的最前沿面板的孩子.

c# visual-studio-2010 windows-forms-designer visual-studio splitcontainer
昨天我在 Visual Studio 的表单设计器中编辑了一个表单。当我今天回到它时,设计师什么也没展示。我可以打开属性窗口,选择所有不同的组成组件并编辑它们的属性,但它们没有显示。应用程序构建良好,表单可以照常运行。
我尝试了几种不同的解决方案,例如检查 .csproj 文件是否包含 form.Designer.cs,但没有任何效果。
奇怪的是,我在本周早些时候确实看到了这个问题,但当我喝完咖啡休息回来后解锁计算机时,它自行修复了。
有什么建议么?
在我的一个项目中,我使用了一个抽象的 UserControl。为了能够在 Visual Studio 中设计此控件,我使用了此答案中提出的代码。现在我想将其与另一个通用的抽象 UserControl 一起使用。但如果我这样做
[TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<MyBaseControl<T>, UserControl>))]
Run Code Online (Sandbox Code Playgroud)
我收到编译器错误
CS0416:属性参数不能使用类型参数
删除类型参数显然也无法编译。
我无法从非泛型基类派生 MyBaseControl,因为它已经从泛型基类派生,因此我尝试用接口装饰它并像这样使用它:
[TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<IMyBaseControl, UserControl>))]
Run Code Online (Sandbox Code Playgroud)
这确实可以编译,但是当我打开设计视图时,我的控件没有被渲染,而是出现错误
提供的泛型参数数量不等于泛型类型定义的数量。
有办法解决这个问题吗?