xenogear

当知道了某样知识之后,就会发现其实什么都不知道

突起效果的Label

现成的Winform下的Label控件的三种BorderStyle没有突起效果的,None, FixedSingle, Fixed3D。
要做个突起效果的,就继承一个Label来做。里面加上:

        protected override CreateParams CreateParams
        
{
            
get
            
{
                CreateParams cp 
= base.CreateParams;
                cp.ExStyle 
&= (~NativeMethods.WS_EXCLIENTEDGE);
                cp.Style 
&= (~NativeMethods.WS_BORDER);

                
switch(borderStyle)
                
{
                    
case BorderStyle.Fixed3D:
                        cp.ExStyle 
|= NativeMethods.WS_EXCLIENTEDGE;
                        
break;
                    
case BorderStyle.FixedSingle:
                        cp.Style 
|= NativeMethods.WS_BORDER;
                        
break;
                }

                
return cp;
            }

        }


        
public override BorderStyle BorderStyle
        
{
            
get
            
{
                
return borderStyle;
            }

            
set
            
{
                
if(borderStyle != value)
                
{
                    
if(!Enum.IsDefined(typeof(BorderStyle), value))
                    
{
                        
throw new InvalidEnumArgumentException("value", (int)value, typeof(BorderStyle));
                    }

                    borderStyle 
= value;
                    UpdateStyles();
                }

            }

        }

看结果,上面那个就是突起的Label
(代码就是MSDN里面那个创建有边框的UserControl的代码,呵呵,只是给不知道的人们看看,我上午就还不知道着呢)

posted on 2004-10-12 20:59  什么都不知道  阅读(1947)  评论(4编辑  收藏  举报

导航