欢迎光临
我们一直在努力

DotNet中不规则窗体的创建方法-.NET教程,Windows开发

建站超值云服务器,限时71元/月

shapedforms
http://www.c-sharpcorner.com/graphics/shaped1.jpg

today windows always appear with a rectangular shape. what if you could have a window that was shaped like a circle, a square or a triangle or any shape you want.
i discovered tonight you could use regions to in effect clip a window to any shape you want. the effect is almost to look like an active desktop component as you cannot move these shaped windows. having done this and created some animation on your desktop i wonder if you could load a bitmap as the basis for your windows. note you lose the titlebars etc but it looks like a useful technique.
here is the source code. apologies if its messy but its been a long night searching for how to do this. i have attached the exe as well for beta 2
enjoy
john
source code:

using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using system.drawing.drawing2d;
namespace shapedform
{
      /// <summary>
      /// summary description for form1.
      /// </summary>
      public class form1 : system.windows.forms.form
      {
            private system.windows.forms.timer timer1;
            private system.componentmodel.icontainer components;
            public float f;           
            public form1()
            {
                  //
                  // required for windows form designer support
                  //
                  initializecomponent();
                   //
                  // todo: add any constructor code after 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 windows form 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.components = new system.componentmodel.container();
                  this.timer1 = new
system.windows.forms.timer(this.components);
                  //
                  // timer1
                  //
                  this.timer1.enabled = true;
                  this.timer1.interval = 50;
                  this.timer1.tick += new system.eventhandler(this.timer1_tick);
                  //
                  // form1
                  //
                  this.autoscalebasesize = new system.drawing.size(5, 13);
                  this.clientsize = new system.drawing.size(292, 273);
                  this.name = "form1";
                  this.text = "form1";
            }
            #endregion
            /// <summary>
            /// the main entry point for the application.
            /// </summary>
            [stathread]
            static void main ()
            {
                  application.run(new form1());
            }
  
            private void timer1_tick(object sender, system.eventargs e)
            {
      this.refresh();
           }
            protected override void onpaint(painteventargs e)
            {
                  graphicspath gp = new graphicspath();
                  gp.addellipse(20,20,110,110);
                  //gp.addline(30,30,110,110);
         
                  matrix rotationtransform = new matrix(1,0, 0,1,1,1);  // rotation matrix
                  //matrix translationtransform = new matrix(1, 0, 0, 1, 0, 0); // translation matrix
                  pointf therotationpoint = new pointf(110.0f, 110.0f);  // rotation point   
                  // rotate the rotation transformation matrix f degrees around therotationpoint
                  rotationtransform.rotateat(f, therotationpoint);   
                  //call the transform method of the graphics path in order to multiply it by the rotation matrix and rotate the balloon
                  gp.transform(rotationtransform);
                  e.graphics.drawpath(pens.black, gp);
                  f=f+10;
                  this.region=new region(gp);
           }   
      }
}

 

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » DotNet中不规则窗体的创建方法-.NET教程,Windows开发
分享到: 更多 (0)