马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
它有很多缺点的,有兴趣可以到网上去搜索一下。于是微软有发明了“下一代”C++:C++/CLI语言,这个可以解决在.NETFramework中,托管C++产生的问题。在《程序员》杂志上,lippman和李建中合作连载介绍了C++/CLI语言。- usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Drawing;usingSystem.Drawing.Imaging;usingSystem.Drawing.Drawing2D;usingSystem.Data;usingSystem.Text;usingSystem.Windows.Forms;namespaceMyControls{publicpartialclassCrystalButton:Button{privateenumMouseActionType{None,Hover,Click}privateMouseActionTypemouseAction;privateImageAttributesimgAttr=newImageAttributes();privateBitmapbuttonBitmap;privateRectanglebuttonBitmapRectangle;publicCrystalButton(){InitializeComponent();mouseAction=MouseActionType.None;this.SetStyle(ControlStyles.AllPaintingInWmPaintControlStyles.DoubleBufferControlStyles.UserPaint,true);//Thefollowingdefaultsarebettersuitedtodrawthetextoutlinethis.Font=newFont("ArialBlack",12,FontStyle.Bold);this.BackColor=Color.DarkTurquoise;this.Size=newSize(112,48);}privateGraphicsPathGetGraphicsPath(Rectanglerc,intr){intx=rc.X,y=rc.Y,w=rc.Width,h=rc.Height;GraphicsPathpath=newGraphicsPath();path.AddArc(x,y,r,r,180,90);//Upperleftcornerpath.AddArc(x+w-r,y,r,r,270,90);//Upperrightcornerpath.AddArc(x+w-r,y+h-r,r,r,0,90);//Lowerrightcornerpath.AddArc(x,y+h-r,r,r,90,90);//Lowerleftcornerpath.CloseFigure();returnpath;}protectedoverridevoidOnPaint(PaintEventArgse){Graphicsg=e.Graphics;//g.Clear(Color.White);g.Clear(SystemColors.ButtonFace);Colorclr=this.BackColor;intshadowOffset=8;intbtnOffset=0;switch(mouseAction){caseMouseActionType.Click:shadowOffset=4;clr=Color.LightGray;btnOffset=2;break;caseMouseActionType.Hover:clr=Color.LightGray;break;}g.SmoothingMode=SmoothingMode.AntiAlias;//////创立按钮自己的图形///Rectanglerc=newRectangle(btnOffset,btnOffset,this.ClientSize.Width-8-btnOffset,this.ClientSize.Height-8-btnOffset);GraphicsPathpath1=this.GetGraphicsPath(rc,20);LinearGradientBrushbr1=newLinearGradientBrush(newPoint(0,0),newPoint(0,rc.Height+6),clr,Color.White);//////创立按钮暗影///Rectanglerc2=rc;rc2.Offset(shadowOffset,shadowOffset);GraphicsPathpath2=this.GetGraphicsPath(rc2,20);PathGradientBrushbr2=newPathGradientBrush(path2);br2.CenterColor=Color.Black;br2.SurroundColors=newColor[]{SystemColors.ButtonFace};//为了更传神,我们将突变停止色彩设定为窗体远景色彩,能够依据窗口的远景色彩得当调剂//////创立按钮顶部红色突变///Rectanglerc3=rc;rc3.Inflate(-5,-5);rc3.Height=15;GraphicsPathpath3=GetGraphicsPath(rc3,20);LinearGradientBrushbr3=newLinearGradientBrush(rc3,Color.FromArgb(255,Color.White),Color.FromArgb(0,Color.White),LinearGradientMode.Vertical);//////绘制图形///g.FillPath(br2,path2);//绘制暗影g.FillPath(br1,path1);//绘制按钮g.FillPath(br3,path3);//绘制顶部红色泡泡//////设定内存位图工具,举行二级缓存画图操纵///buttonBitmapRectangle=newRectangle(rc.Location,rc.Size);buttonBitmap=newBitmap(buttonBitmapRectangle.Width,buttonBitmapRectangle.Height);Graphicsg_bmp=Graphics.FromImage(buttonBitmap);g_bmp.SmoothingMode=SmoothingMode.AntiAlias;g_bmp.FillPath(br1,path1);g_bmp.FillPath(br3,path3);//////将region赋值给buttonRegionrgn=newRegion(path1);rgn.Union(path2);this.Region=rgn;//////绘制按钮的文本///GraphicsPathpath4=newGraphicsPath();RectangleFpath1bounds=path1.GetBounds();RectanglercText=newRectangle((int)path1bounds.X+btnOffset,(int)path1bounds.Y+btnOffset,(int)path1bounds.Width,(int)path1bounds.Height);StringFormatstrformat=newStringFormat();strformat.Alignment=StringAlignment.Center;strformat.LineAlignment=StringAlignment.Center;path4.AddString(this.Text,this.Font.FontFamily,(int)this.Font.Style,this.Font.Size,rcText,strformat);PentxtPen=newPen(this.ForeColor,1);g.DrawPath(txtPen,path4);g_bmp.DrawPath(txtPen,path4);}protectedoverridevoidOnMouseDown(MouseEventArgse){if(e.Button==MouseButtons.Left){this.mouseAction=MouseActionType.Click;this.Invalidate();}base.OnMouseDown(e);}protectedoverridevoidOnMouseUp(MouseEventArgse){this.mouseAction=MouseActionType.Hover;this.Invalidate();base.OnMouseUp(e);}protectedoverridevoidOnMouseHover(EventArgse){this.mouseAction=MouseActionType.Hover;this.Invalidate();base.OnMouseHover(e);}protectedoverridevoidOnMouseEnter(EventArgse){this.mouseAction=MouseActionType.Hover;this.Invalidate();base.OnMouseEnter(e);}protectedoverridevoidOnMouseLeave(EventArgse){this.mouseAction=MouseActionType.None;this.Invalidate();base.OnMouseLeave(e);}}}
复制代码 完全不一样的。.net其实我也说不太清,.net可以把他理解为跟J2EE相对的工具。c++主要做系统相关的开发你要学.net的话就应该学C#。(其实微软在.NET平台上也考虑了给C++留一个地位。 |