Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / April 2005

Tip: Looking for answers? Try searching our database.

"RUN MODE" of Usercontrol get activated at Designtime

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jaini - 06 Apr 2005 08:22 GMT
Hi All,

          I have created a simple usercontrol(using c#,the code is
added below).Now at designtime(Windows forms) i add this usercontrol
into a Panel(or any container Controls).Now i drag the user control
out of my Panel.(now the control is on the form).At this moment the
runtime mode of the control is get activated.(like in this case the
usercontrol contains a textbox and user can type in the information
into the textbox, as if it is in run mode.

Regards
Anand

//******************** Source code of user control ****************

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace WindowsControlLibrary2
{
    /// <summary>
    /// Summary description for UserControl2.
    /// </summary>
    public class UserControl2 : System.Windows.Forms.UserControl
    {
        private System.Windows.Forms.TextBox textBox1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public UserControl2()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            // TODO: Add any initialization after the InitializeComponent call

        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Component Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            //
            // textBox1
            //
            this.textBox1.Location = new System.Drawing.Point(8, 8);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(136, 20);
            this.textBox1.TabIndex = 0;
            this.textBox1.Text = "textBox1";
            //
            // UserControl2
            //
            this.Controls.Add(this.textBox1);
            this.Name = "UserControl2";
            this.Size = new System.Drawing.Size(150, 32);
            this.ResumeLayout(false);

        }
        #endregion
    }
}
Beth Massi [Architect MVP] - 13 Apr 2005 16:54 GMT
Yes, this is by design. The constructor and the Load event (and dispose,
etc) are always run even in design mode. If the controls did not initialize
then you wouldn't see them at design-time. If you have code in your Load
event handler that you do not want to run at design-time of the control
itself then test for Me.DesignMode. That will return true if the particular
control is being designed.

If you have code that you do not want to run when ANY parent control is in
design-mode (which is probably a more likely scenario -- like when you drop
the user control on a form that's being designed) then you can put this code
in your base usercontrol class to test if any control it's sitting on is in
design mode:

Public Shared Function IsDesignMode(ByVal c As Control) As Boolean
 '--Return's true when in the designer regardless if whether code is
running or not.
 If c Is Nothing Then Return False
 If c.Created Then
  If Not (c.Site Is Nothing) AndAlso c.Site.DesignMode Then Return True
 Else
  If (System.Reflection.Assembly.GetEntryAssembly Is Nothing) Then Return
True
 End If
 Return IsDesignMode(c.Parent)
End Function

To use it, in your user control's code test for IsDesignMode(Me) instead of
Me.DesignMode.

HTH,
-B

> Hi All,
>
[quoted text clipped - 84 lines]
> }
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.