Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Setting Properties on Controls in Inherited Forms
Message
 
À
27/10/2003 16:08:53
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00842236
Message ID:
00843283
Vues:
24
>Morgan,
>
>Thanks so much for all of your help but I’m just not getting it.
>
>I have heard twice that when an object, textbox, button etc is dragged from the toobar to a window’s form that by default the control is private to the form. Therein lies my problem. If I create a new form inheriting from this form with it’s controls then because the controls where private when dragged onto the first form their properties can not be changed in the new form.
>
>Where and how, in the base class form code, do I override this .Net default behavior and make a control on the form public so it’s properties can be changed in the inheriting form? The only place I see any generated code is in the “Windows Form Designer Generated Code” and I don’t see any code instantiating the controls.
>
>
>Terry Carroll

You do know that you can change the accessor of the field inside of the source right?
protected System.Windows.Forms.Button MyButton;

change to
public System.Windows.Forms.Button MyButton;
And pow, it works. Here I will give you a full example of a form.
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace MyForm
{
	public class MyForm : System.Windows.Forms.Form
	{
		public Button OKButton;
		public Button CancelButton;
		private System.ComponentModel.IContainer components = null;

		public MyForm()
		{
			InitializeComponent();
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Designer generated code
		private void InitializeComponent()
		{
			this.OKButton = new Button();
			this.cmdCancel = Button();
			this.SuspendLayout();
			// 
			// OKButton
			// 
			this.OKButton.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.OKButton.Location = new System.Drawing.Point(136, 232);
			this.OKButton.Name = "OKButton";
			this.OKButton.Rule = "";
			this.OKButton.TabIndex = 0;
			this.OKButton.Text = "OK";
			// 
			// CancelButton
			// 
			this.CancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.CancelButton.Location = new System.Drawing.Point(216, 232);
			this.CancelButton.Name = "CancelButton";
			this.CancelButton.Rule = "";
			this.CancelButton.TabIndex = 1;
			this.CancelButton.Text = "Cancel";
			// 
			// MyDialogForm
			// 
			this.AcceptButton = this.cmdOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.CancelButton = this.cmdCancel;
			this.ClientSize = new System.Drawing.Size(402, 279);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
		 this.CancelButton, this.OKButton});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "MyForm";
			this.ResumeLayout(false);

		}
		#endregion


    }
}
Ok, I hope that works. I can't really help you anymore then that.

Morgan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform