[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 483
  • Last Modified:

Derived Panel using PanelContainerDesigner accepts drop - but how can I respond to the drop?

My derived panel control accepts other controls dropped on it at design time -- but then how do I gather these dropped controls into some sort of collection and how do I interact with them programmatically at design time?  How do I "get to" these dropped controls that are now inside my derived panel?
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Web.UI.Design;
using System.Web.UI.Design.WebControls;
 
 
 
 
namespace AJAXEnabledWebApplication1
{
    [DesignerAttribute(typeof(GPBoxDesigner)),
  ToolboxData("<{0}:GPBox runat=\"server\"></{0}:GPBox>")]
 
    public class GPBox : Panel
    {
        public GPBox()
        {
            this.BorderStyle = BorderStyle.Solid;
            this.BorderWidth = 1;
            this.Width = 300;
            this.Height = 300;
 
            GPBoxDesigner.WasClicked += null;
            GPBoxDesigner.WasClicked += new EventHandler(this.RespondToClick);
        }
 
        private void RespondToClick(object sender, EventArgs e)
        {
            string a = "responding to click";
        }
 
        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
 
        }
    }
 
 
 
    public class GPBoxDesigner : PanelContainerDesigner
    {
        public static event EventHandler WasClicked;
 
        private GPBox _gpb = null;
        private static bool clicked = false;
        public string _color = "Green";
 
        public override void Initialize(IComponent component)
        {
            if (!(component is GPBox))
                throw new ArgumentException();
 
            _gpb = (GPBox)component;
            base.Initialize(component);
        }
 
        public override string GetDesignTimeHtml()
        {
            //background-color:Red
            string temp = "<div id='GPBox1' style='background-color:" + _color + ";border-width:1px;border-style:Solid;height:300px;width:300px;'>";
            //return string.Format(temp, _gpb.Style);
            return temp;
        }
 
        public override bool AllowResize
        {
            get
            {
                return true;
                //return base.AllowResize;
            }
        }
 
        // Provide a design-time caption for the panel.
        public override string FrameCaption
        {
            get
            {
                // If the FrameCaption is empty, use the panel control ID.
                string localCaption = base.FrameCaption;
                if (localCaption == null || localCaption == "")
                    localCaption = ((Panel)Component).ID.ToString();
 
                return localCaption;
            }
        } // FrameCaption
 
        // Provide a design-time border style for the panel.
        public override Style FrameStyle
        {
            get
            {
                Style styleOfFrame = base.FrameStyle;
 
                // If no border style is defined, define one.
                if (styleOfFrame.BorderStyle == BorderStyle.NotSet ||
                    styleOfFrame.BorderStyle == BorderStyle.None)
                    styleOfFrame.BorderStyle = BorderStyle.Groove;
 
                return styleOfFrame;
            }
        } // FrameStyle
 
        
        protected override void OnClick(DesignerRegionMouseEventArgs e)
        {
            base.OnClick(e);
 
            if (clicked == true)
            {
                _color = "Red";
            }
            else
            {
                _color = "Blue";
            }
 
            clicked = !clicked;
 
            GetDesignTimeHtml();
 
            if (WasClicked != null)
            {
                WasClicked(_color, null);
            }
            
        }
    }
}

Open in new window

0
Tom Knowlton
Asked:
Tom Knowlton
1 Solution
 
Bob LearnedCommented:
Tom,

You can access to controls in the GPBoxDesigner with the AssociatedComponents property.

Bob
0
 
SteveH_UKCommented:
Could you post how you used the solution?  It would be good to know, thanks!
0
 
Tom KnowltonWeb developerAuthor Commented:
I haven't implemented it yet.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now