在另一个问题中,我询问了为某些运行时编译器部署本地化UserControl的问题.但是,在我可以部署本地化之前,我需要一种本地化控件的方法.
控件由我们自己的WinForms风格的设计器创建(使用.NET对设计图面的支持等),并保存为二进制格式,将CodeCompileUnit资源resx和用户源组合到一个文件中.然后,这些文件在运行时由另一个工具适当地编译到程序集中.
为了本地化这些,我们需要告诉设计者和序列化,可本地化的属性值将存储在资源中.VisualStudio WinForms设计器使用名为的扩展属性Localizable和用于指定默认区域性的关联属性来执行此操作.如果可能的话,我们在自定义设计器中需要这个属性.
我们需要我们的独立设计器工具,它易于用于非开发人员类型以及限制某些操作,因此使用Visual Studio的免费版本(即C#Express)是行不通的(我已经支持它并且失败了) ; 因此,我们如何本地化这些UserControl需要的任何解决方案来弥补这一点.
我们可以在我们的自定义WinForms设计器中获得Localizable支持吗?
UserControl的?例如,以某种方式后处理,不同的文件格式等.localization internationalization windows-forms-designer winforms c#-2.0
我们实施了新的编码标准,要求我们的私人会员拥有领先的下划线.像这样:
private System.Windows.Forms.Label _label;
Run Code Online (Sandbox Code Playgroud)
不幸的是,当您将新标签拖到表单上时,VS将在下面输出默认值:
private System.Windows.Forms.Label label1;
Run Code Online (Sandbox Code Playgroud)
有没有办法将默认值更改为:
private System.Windows.Forms.Label _label1;
Run Code Online (Sandbox Code Playgroud)
这适用于所有控件,而不仅仅是标签,是的,它们将从代码中使用.
干杯,
普拉门
c# code-generation windows-forms-designer visual-studio winforms
当我使用C#在Visual Studio中开发Windows窗体应用程序时,我添加到窗体的每个控件都默认标记为private,这就是我想要的.
使用VB.NET时,默认情况下每个控件都标记为Friend(相当于internalC#),这不是我想要的.
我可以更改此默认值吗?看起来肯定是某个地方的设置.
vb.net visual-studio-2008 windows-forms-designer visual-studio
我在我的Windows窗体项目中的控件上使用的资源文件中有一些资源(在这种情况下是图像).Visual Studio资源选择对话框不能很好地支持从资源文件中选择图像,除非它们位于特定位置,但您可以直接编辑设计器文件,这样就可以了.应用程序编译并正确运行,Windows窗体设计器足够智能,不会搞砸我手工编辑的代码.
// in an assembly named ResourceConsumer
this.button1.Image = global::ResourceConsumer.Properties.Resources.Close32x32;
Run Code Online (Sandbox Code Playgroud)
现在我想将这些资源移动到外部程序集,以便多个应用程序可以使用它们.我可以设置一个程序集来公开它的资源而没有问题(只要我使用的是Visual Studio 2008或更高版本),这样就可以了.当我更改设计器代码以从其新位置引用图像时,代码会编译并正确运行,但现在Windows窗体设计器会在生成代码时更改我的代码; 它将图像的二进制文件嵌入本地资源文件中并从那里引用它.
// ResourceProducer is an external assembly containing resources
this.button1.Image = global::ResourceProducer.Properties.Resources.Exit32x32;
Run Code Online (Sandbox Code Playgroud)
由Windows窗体设计器更改为:
this.button1.Image = ((System.Drawing.Image)(resources.GetObject("button1.Image")));
Run Code Online (Sandbox Code Playgroud)
Windows窗体设计器似乎理解从同一个程序集中提取资源,而不是从外部提取资源.有没有办法让Windows窗体设计器允许我使用外部程序集中的资源?
所有,
我已经完成了GUI设计阶段......现在我已经开始为我的应用程序中的所有控件添加有意义的名称.每当我点击控件改变它的名字时,Visual Studio就会让我疯狂自动生成事件(好吧所以只有当我搞砸了,双击......但仍然很烦人时).
有没有办法暂时禁用此功能?我仍然想要它,因为当我编码时它是一个很好的捷径.
谢谢!
我找不到在Windows窗体按钮中缩放图像的方法.请参阅下面DPI 200%上显示的Windows窗体设计器的样子(我知道Windows窗体设计器应仅用于DPI 100%/ 96,此屏幕截图只是说明了我的观点).
当按钮大小正确缩放(34x33)时,按钮大小中的图像不会缩放/拉伸/缩放(它仍然是16x16).我做了很多尝试来解决这个问题:
AutoScaleMode设置为Font,将其设置为Dpi不能使其工作.AutoSize为true或false不使其工作.AutoSizeMode为任何值都不起作用.Button.ImageLayout可以设置为Stretch或Zoom.App.Config设置<add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />无法使其正常工作.FlatStyle或ImageAlign不使其工作.你是如何在你的应用中解决这个问题的?

有两种形式.Form2源自Form1.
但是我在设计模式下遇到了Form2的问题,如下面的屏幕截图所示.
如果我对此发表评论this._presenter.Retrive();,它将正常工作.是怎么回事以及如何解决这个问题?
UPD: 如果我将删除throw new NotImplementedException(); 并将插入,例如,MessageBox.Show("Test");,每次我打开Form2时,MessageBox都会出现,就像我运行应用程序一样.
窗体2
namespace InheritanceDemo
{
public partial class Form2 : Form1
{
public Form2()
{
InitializeComponent();
}
}
}
Run Code Online (Sandbox Code Playgroud)
Form1中
namespace InheritanceDemo
{
public partial class Form1 : Form
{
protected IPresenter _presenter;
public Form1()
{
InitializeComponent();
_presenter = new Presenters();
}
private void Form1_Load(object sender, EventArgs e)
{
this._presenter.Retrive();
}
}
public class Presenters : IPresenter
{
public void Retrive()
{
throw new NotImplementedException(); …Run Code Online (Sandbox Code Playgroud) 我的问题不是如何在设计时进行调试。我实际上想通过设计器中可用的事件进行调试。我知道表单有加载和其他类型的事件。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) winforms ×8
c# ×6
.net ×3
button ×1
c#-2.0 ×1
datagridview ×1
debugging ×1
dpi ×1
inheritance ×1
localization ×1
resources ×1
scale ×1
vb.net ×1