控制自定义控件设计时的表现

 最近做一个自定义控件,控件里有一个隐藏的div,在设计时会把不整个页面撑开,甚至是aspx在设计与html切换时会改变整个面页的布局,如何解决这个问题.自已搞了很久没有搞定,后来在csdn里请高手解决了.http://community.csdn.net/Expert/topic/4930/4930751.xml?temp=.9275324

在csdn提问之前我也在msdn里找到了下面这个帮助,但由于比较急,没有细看.呵呵,以后做事一定保持平静,这样可能会少走弯路.

还有,System.Web.UI.Design需要引进System.Design.dll

 

using  System;
using  System.Web.UI;
using  System.Web.UI.Design;
using  System.Web.UI.WebControls;
using  System.ComponentModel;
using  System.ComponentModel.Design;

namespace  WebControlDesignerExample
{    
    
// This control designer offers designer verb menu commands
    
// that can alter the design time html provided for the 
    
// System.Web.UI.Control this designer supports.
    public class TextSizeWebControlDesigner : System.Web.UI.Design.ControlDesigner
    
{
        
// Whether to display the html of the associated 
        
// control using a large heading text size.
        private bool LargeText;        

        
public TextSizeWebControlDesigner() : base()
        
{
            LargeText 
= false;                  
        }


        
// Provides a menu command to toggle the text size.
        public override System.ComponentModel.Design.DesignerVerbCollection Verbs
        
{
            
get
            
{
                DesignerVerbCollection dvc 
= new DesignerVerbCollection();
                
if( LargeText )
                    dvc.Add( 
new DesignerVerb("Reduce text size"new EventHandler(this.toggleTextSize)) );
                
else
                    dvc.Add( 
new DesignerVerb("Enlarge text size"new EventHandler(this.toggleTextSize)) );
                
return dvc;
            }

        }


        
// Returns the html to use to represent the control at design time.
        public override string GetDesignTimeHtml()
        
{
            
string html = base.GetDesignTimeHtml();

            
if( LargeText )
                
return "<H1>"+html+"</H1>";
            
else
                
return "<H3>"+html+"</H3>";                        
        }
        

        
// Event handler to toggle whether the html receives a large or 
        
// small size heading markup tag.
        private void toggleTextSize(object sender, EventArgs e)
        
{
            
if( LargeText )
                LargeText 
= false;
            
else
                LargeText 
= true;
            
this.IsDirty = true;
            
this.UpdateDesignTimeHtml();
        }
        
    }


    
// Simple text web control renders a text string.
    
// This control is associated with the TextSizeWebControlDesigner.
    [DesignerAttribute(typeof(TextSizeWebControlDesigner), typeof(IDesigner))]
    
public class TextControl : System.Web.UI.WebControls.WebControl
    
{
        
private string text;

        [Bindable(
true),
            Category(
"Appearance"),
            DefaultValue(
"")]
        
public string Text
        
{
            
get
            
{
                
return text;
            }


            
set
            
{
                text 
= value;
            }

        }


        
public TextControl()
        
{
            text 
= "Test phrase";
        }


        
protected override void Render(HtmlTextWriter output)
        
{
            output.Write(Text);
        }

    }
    
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值