Tag: 用户控件

重建用户控件时,用户控件自定义属性会丢失状态

我有一个自定义属性的用户控件,如下所示: [DefaultValue(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] [Description(“Gets or sets whether the \”Remove\” button is visible.”)] public bool ShowRemoveButton { get { return this.removeButton.Visible; } set { this.removeButton.Visible = value; } } 该控件包含一个标准按钮控件。 此属性用于显示或隐藏按钮。 用户控件构建在单独的项目程序集中。 我把它放在一个表格上,我可以设置和取消设置上面的属性,一切似乎都工作得很好。 但是,当重建包含用户控件的项目时,属性值将翻转为“false”,这不是默认值。 在重建控件时,如何防止自定义属性丢失/更改其状态?

如何在C#中创建横幅面板?

我想创建自己的自定义控件,它基本上是一个包含3行和1列的TableLayoutPanel。 顶部和底部行将包含标签(横幅),中间行是我将添加其他控件的位置。 问题是,当我尝试从此控件构建其他窗体/控件时,设计器无法识别中间面板。 我怎么得到它? 如果我将文本框拖到中间并设置Dock = Fill,它将覆盖entrie表单/控件。 此外,有没有办法让设计师拒绝将控件拖动到顶部和底部(横幅)行? 我已经尝试了以下链接中的步骤,但没有任何运气( http://support.microsoft.com/?scid=kb%3Ben-us%3B813450&x=21&y=15 )。

如何从用户控件调用方法到aspx页面?

我想调用从用户控件到aspx页面的方法 我正在尝试,但我无法在aspx页面中调用该方法 码: AddVisaUserControl.ascx.cs public event EventHandler UserControlButtonClicked; public void OnUserControlButtonClick() { if (UserControlButtonClicked != null) { UserControlButtonClicked(this,EventArgs.Empty); } } protected void btnRemove_Click(object sender, EventArgs e) { OnUserControlButtonClick(); } 的.aspx 编辑 在下面的代码页面加载时我得到“空引用错误” AddVisaControl av; protected void Page_Load(object sender, EventArgs e) { av.UserControlButtonClicked += new EventHandler(AddVisaUserControl_UserControlButtonClicked); } private void AddVisaControl_UserControlButtonClicked(object sender, EventArgs e) { var ctrl […]

将值传输到动态加载的Web用户控件

我有ASPX页面在preinit我检查whitch用户控件加载。 control = “~/templates/” + which + “/master.ascx”; 然后在pageload上,我加载该控件 Control userControl = Page.LoadControl(control); Page.Controls.Add(userControl); 我怎样才能将动态加载的用户控件从aspx转移到ascx?

如何使用WPF用户控件关闭父窗口

假设我有两个WPF窗口:window_One和window_Two。 window_One有一个按钮。 单击此按钮将打开window_Two。 window_Two包含一个用户控件。 该用户控件有一个关闭window_Two的按钮。 我该如何实现这种情况?

设置控制父属性和使用Controls.Add()之间的区别?

更具体地说,是这些陈述 ownerControl.GroupBox1.Controls.Remove(childControl); ownerControl.Controls.Add(childControl); 相当于 childControl.Parent = ownerControl;

如何在inheritance的ControlDesigner类中获取ITypeDescriptorContext和IServiceProvider

我已将ControlDesigner类inheritance到MyControlDesigner 。 在这个类中,我需要获取ITypeDescriptorContext和IServiceProvider接口背后的对象,但我不知道如何:( 我需要这两个接口在方法中传递它们,但我无法在任何其他对象中找到它们。 有人能帮帮我吗。 谢谢 最好的问候Bojan

UserControl中的ConfigurationManager连接字符串为null

我有一个应用程序通过数据层获取数据到表单,使用这样的东西: public DataTable get(String query, ArrayList parameters = null) { using (iDB2Connection cn = new iDB2Connection(ConfigurationManager.ConnectionStrings[“iseries”].ToString())) { // get the data and return them } } 我有获取数据的表单,这很好用。 但是,我创建了一个UserControl,它通过这个方法获取数据,当我运行我的项目时工作正常,但是,包含UserControl的表单会引发设计器exception。 “为了防止在加载设计器之前丢失数据,必须解决以下错误:” 我发现错误位于从检索连接字符串时。 它会抛出nullpointerexception。 但仅限于设计模式。 当我忽略它时,一切正常,但是,我想知道如何解决这个问题。 通过我的UserControl访问它们时,为什么我的 null? 更新1 似乎我的UserControl根本无法识别 。 当我将此代码放入UserControl Load事件时,我也得到了一个null引用。 private void SelectUser_Load(object sender, EventArgs e) { txtLocation.Text = ConfigurationManager.AppSettings[“location”].ToString(); }

如何在自定义用户控件上创建单击事件?

我已经创建了一个自定义用户控件。 我是否可以添加单击事件,以便当有人单击控件区域中的任何位置时,会触发单击事件? 用户控件定义为: XAML: C#: public partial class TabItem : UserControl { public static readonly DependencyProperty ImageProperty = DependencyProperty.Register(“TabItemImage”, typeof(string), typeof(TabItem), null); public static readonly DependencyProperty TextProperty = DependencyProperty.Register(“TabItemText”, typeof(string), typeof(TabItem), null); public string TabItemImage { get { return (string)GetValue(ImageProperty); } set { SetValue(ImageProperty, value); } } public string TabItemText { get { return (string)GetValue(TextProperty); […]

UserControl中的EF无法看到app.config?

我刚刚创建了一个用户控件。 此控件还使用我的静态Entity Framework类来加载两个combobox。 一切都很好,运行没有问题。 设计和运行时正在运行。 然后,当我停止应用程序时,包含我的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; } } } 我的UserControl中发生了一些逻辑,用于加载combobox中的数据: private void LaadCbx() { cbxCategorie.DataSource = […]