这一直是我的问题:如何让Windows Forms设计器为我正在处理的表单的水平和垂直中心提供像素捕捉?
我刚刚创建了一个用户控件.此控件还使用我的静态实体框架类来加载两个组合框.一切都很好,运行没有问题.设计和运行时正在运行.然后,当我停止应用程序时,包含我的UserControl的所有表单在设计时不再有效.我只看到两个错误:
错误1:在配置中找不到指定的命名连接,不打算与EntityClient提供程序一起使用,或者无效.
错误2:变量ccArtikelVelden未声明或从未分配.(ccArtikelVelde是我的UserControl)
运行时一切都还在运行
我的静态EF Repositoy类:
public class BSManagerData
{
private static BSManagerEntities _entities;
public static BSManagerEntities Entities
{
get
{
if (_entities == null)
_entities = new BSManagerEntities();
return _entities;
}
set
{
_entities = value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的UserControl中发生了一些逻辑,用于加载组合框中的数据:
private void LaadCbx()
{
cbxCategorie.DataSource = (from c in BSManagerData.Entities.Categories
select c).ToList();
cbxCategorie.DisplayMember = "Naam";
cbxCategorie.ValueMember = "Id";
}
private void cbxCategorie_SelectedIndexChanged(object sender, EventArgs e)
{
cbxFabrikant.DataSource = from f in BSManagerData.Entities.Fabrikants
where f.Categorie.Id == …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 …
我继承了ControlDesigner班级MyControlDesigner.
在这个类我需要获取后面的对象ITypeDescriptorContext和IServiceProvider接口,但我不知道如何:(
我需要这两个接口在方法中传递它们,但我无法在任何其他对象中找到它们.
有人能帮帮我吗.
谢谢
最好的问候Bojan
我有一个框架,其中包含许多基类,可以派生它们来开发许多应用程序.在这些类中有一个System.Windows.Forms.Panel的子类,我为它编写了自己的设计器.Visual Studio 2005一切正常,但当我尝试迁移到VS2010时出现问题.这是我正在做的简化版本:
我有一个名为CoreClasse的项目,它包含一个接口和两个类:
public interface IConf
{
string foo { get; set; }
void InitFoo();
}
public class SimpleClass
{
public string foo;
}
public class ConfLoader
{
public static IConf LoadConf()
{
AssemblyName anAssemblyName = new AssemblyName("ConfClasses");
Assembly anAssembly = Assembly.Load(anAssemblyName);
IConf result = (IConf)anAssembly.CreateInstance("ConfClasses.ConfClass");
result.InitFoo();
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
然后有一个项目ConfClasses引用CoreClasses并且只包含一个实现IConf的类:
public class ConfClass : IConf
{
public SimpleClass confVal;
public string foo
{
get { return confVal.foo; }
set { confVal.foo = value; }
}
public void …Run Code Online (Sandbox Code Playgroud) 我使用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
我正在关注winforms的这个教程,到目前为止,教程正在编写表单而不使用工具箱.我相信它很快就会更深入地介绍工具箱.
在本教程之后,我在以下两段代码中进行了部分类:
第一档:
using System;
using System.Windows.Forms;
public class Numeric : System.Windows.Forms.TextBox
{
public Numeric()
{
}
}
public partial class Exercise
{
private Numeric txtbox;
System.ComponentModel.Container components;
}
Run Code Online (Sandbox Code Playgroud)
第二档:
using System;
using System.Windows.Forms;
public partial class Exercise : Form
{
private void InitializeComponent()
{
txtbox = new Numeric();
Controls.Add(txtbox);
}
public Exercise()
{
InitializeComponent();
}
}
public class program
{
public static int Main()
{
Application.Run(new Exercise());
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
当我用F5运行代码时,一切看起来都很好:表单弹出文本框.
但出于某种原因,当我右键单击第二个文件并选择"视图设计器"时,我收到一条错误,上面写着"变量'txtbox'未声明或未被分配".我可以选择"忽略并继续",这会将我引导到一个没有文本框的表单.
为什么会这样?我知道有些人认为我应该使用工具箱,这可能是最明智的做法,但我仍然想知道为什么会这样.
我有一个项目,其中包含从基本形式(称为frmBase)继承属性的表单.我遇到了一个令我困惑的问题:
我希望程序以用户屏幕为中心,所以我补充说
this.CenterToScreen();
到frmBase_Load().当我运行应用程序时,这很有效,但是,当我尝试设计从frmBase继承的任何表单时,它们都被移动到设计器屏幕的右下角,我必须使用滚动条来查看它们.
如果我搬家了
this.CenterToScreen();
对于frmBase()代码,app在运行时默认为屏幕的左上角,但设计者会正确地为我显示表单.知道发生了什么事吗?我搜索过,但似乎找不到类似的问题,虽然我知道我不能成为第一个发生这种情况的人.....