創建任意窗體代碼


            //初始化一個GraphicsPath類的對象
            System.Drawing.Drawing2D.GraphicsPath myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
            //確定一個字符串,該字符串就是控件的形狀
            string stringText = "Do you know who is xiaopeng?";
            //確定字符串的字體
            FontFamily family = new FontFamily("宋體");
            //確定字符串的風格
            int fontStyle = (int)FontStyle.Bold;
            //確定字符串的高度
            int emSize = 35;
            //確定字符串的起始位置,它是從控件開始計算而非窗體
            PointF origin = new PointF(0, 0);
            //一個StringFormat對象來確定字符串的字間距以及對齊方式
            StringFormat format = new StringFormat(StringFormat.GenericDefault);
            //用AddString方法創建字符串
            myGraphicsPath.AddString(stringText, family, fontStyle, emSize, origin, format);
            //將控件的Region屬性設置爲上面創建的GraphicsPath對象
            this.Region = new Region(myGraphicsPath);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章