Java正則表達式婚配德律風格局。本站提示廣大學習愛好者:(Java正則表達式婚配德律風格局)文章只能為提供參考,不一定能成為您想要的結果。以下是Java正則表達式婚配德律風格局正文
本文實例講述了winform異型不規矩界面設計的完成辦法,用於界面設計時有不錯的用戶體驗,異常適用。分享給年夜家供年夜家參考之用。詳細辦法以下:
1、不規矩WINFORM窗體
Author:unknown From:Internet
在之前版本的Visual Basic或Visual C++中,創立不規矩窗體和控件是一件很龐雜的事,不只須要挪用年夜量API函數並且任務量也不小。不外,如今在Visual C#下,情形就完整分歧了。應用Windows Forms你便可以很隨意馬虎地創立出一個不規矩的窗體和窗體上的控件。一個具有不規矩窗體和控件的運用法式確定會更吸引寬大的用戶,微軟的Windows Media Player 7就顯示出這一點。作為法式員,您必定想在本身的法式中應用這點技巧吧。
法式的窗體和控件都可以以非傳統的方法被創立。本文就向年夜家展現若何在運用法式中創立不規矩窗體,和若何在窗體上創立林林總總的自界說外形的控件。
注:創立不規矩窗體和控件這個進程包括了年夜量的圖形編程任務,所以分歧的盤算機因內存和顯卡的分歧能夠會招致終究的後果有所分歧。是以,在宣布你的運用法式前,務必在各類分歧類型的盤算機上做好測試任務。
完成辦法:
起首,創立一個位圖文件作為法式的窗體。位圖可所以隨意率性外形的,然則位圖文件區域必定要足夠年夜,如許能力包括窗體上的一切控件。然後,你可以經由過程設置一些屬性使該圖成為法式的窗體。
把法式中的題目欄去失落,不然全部界面將顯得很不調和。固然你去失落了題目欄也就去失落了它的最年夜化、最小化、封閉、挪動窗體等功效。為了使法式依然具有這些功效,我們需在法式中添加一些代碼,如許用戶就依然可以像之前一樣和法式停止交互。
是以,你須要完成以下任務:
1.創立一個作為窗體的位圖文件。
2.創立一個Windows運用法式,用上述位圖文件作為法式的窗體同時去失落其題目欄。
3.添加原題目欄具有的功效所需的代碼。
詳細步調:
上面我就詳細向年夜家引見若何創立不規矩窗體。
創立一個具有不規矩外形的位圖文件
1.用任何繪圖法式便可以創立不規矩外形的位圖,你可使用最輕易也是最便利的繪圖法式。
2.用一種色彩畫出一個不規矩的區域作為法式的窗體,並用另外一種色彩畫出該位圖的配景。(你要使該不規矩區域足夠年夜。)
3.保留位圖文件。
上面就是一個例子:
在vs.net中創立一個新的工程:
起首,設置窗體的配景從而樹立窗體外形。
1.在窗體設計器當選中窗體使之取得核心。
2.在屬性對話框中停止以下設置:
●將FormBorderStyle屬性設置為None。該屬性去失落了法式的題目欄,同時也除去了題目欄的功效,不外我在前面還會向年夜家引見若何添加代碼以恢復這些功效的。
●將BackgroundImage屬性設置為你創立的位圖文件。你不用在工程中添加該文件,由於你一旦指定了該文件,它就會主動被添加到工程中。
●將TransparencyKey屬性設置為位圖文件的配景色彩值(在本例中是藍色)。該屬性使得位圖的配景即上圖中的藍色部門弗成見,從而窗體就出現出一個不規矩的卵形。
3.保留工程。按Ctrl+F5可以運轉此法式。(注:由於沒有題目欄,所以你可以經由過程Alt+F4來封閉法式)
將FormBorderStyle屬性設置為None後,法式的題目欄就被去失落了。如許,為了取得本來題目欄的功效,我們必需手動添加代碼。上面我就向年夜家引見若何添加代碼完成封閉功效和挪動窗體的功效。
完成窗體的封閉及挪動:
1.往窗體上拖放一個按鈕控件。
2.在屬性對話框中,將該控件的Text屬性設置為“封閉”。
3.雙擊按鈕添加一個Click事宜處置函數。
4.在代碼編纂器中添加以下代碼:
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
2、不規矩按鈕Author:unknown From:Internet如今,我們曾經創立了一個不規矩的窗體,並完成了一些根本的挪動窗體、封閉窗體的功效。但是,窗體上的按鈕控件照樣老一套,那末方樸直正,使得全部界面不雅觀。接上去我就向年夜家引見若何創立自界說外形的控件。 後面我們創立不規矩窗體的時刻用到了TransparencyKey屬性,然則控件是沒有該屬性的,所以我們得找其他的辦法來完成控件的不規矩外形了。在窗體上畫一個自界說外形的控件時,你須要准確的告訴窗體在甚麼地位和若何畫該控件。在.Net Framework中有響應的類和辦法來幫你完成這些,所以你不用擔憂詳細完成。 .Net Framework中的類供給給控件一個指導解釋,該指導解釋能肯定控件被畫的外形。經由過程分歧的指導解釋,你便可以按你想要的辦法來畫控件了。該指導解釋應用了GraphicsPath這個類,這個類代表了一系列用來繪圖的直線和曲線。起首,你得指定一個GraphicsPath類的對象並告訴它你要畫甚麼圖形。然後,你將控件的Region屬性設置為上述GraphicsPath類的對象。如許,你便可以創立任何自界說外形的控件了。
步調以下:
● 創立一個GraphicsPath類的實例對象。
● 指定好該對象的各項細節(如年夜小、外形等等)。
● 將控件的Region屬性設置為下面樹立的GraphicsPath類的實例對象。 創立一個像文本的按鈕控件:
1.拖放一個按鈕控件到窗體上。
2.在屬性對話框中停止以下設置:
● 將Name屬性設置為CustomButton。
● 將BackColor屬性設置為一個和窗體配景色彩分歧的色彩值。
● 將其Text屬性設置為空字符串。
3.添加窗體的Paint事宜的事宜處置函數。
4.添加以下代碼,用GraphicsPath類的實例對象來畫控件。
上面的代碼以一串字符串的情勢畫該按鈕控件,同時,法式還設置了字符串的字體、年夜小、作風等屬性。字符串被賦給GraphicsPath類的實例對象。然後,該實例對象就被設置為按鈕控件的Region屬性。如許一個自界說外形的控件就完成了。
private void CustomButton_Paint( object sender, System.Windows.Forms.PaintEventArgs e )
{
//初始化一個GraphicsPath類的對象
System.Drawing.Drawing2D.GraphicsPath myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
//肯定一個字符串,該字符串就是控件的外形
string stringText = "Click Me!";
//肯定字符串的字體
FontFamily family = new FontFamily("Arial");
//肯定字符串的作風
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對象
CustomButton.Region = new Region(myGraphicsPath);
}
3、GDI+編程的10個根本技能
//創立畫圖外面有兩種經常使用的辦法。上面想法獲得PictureBox的畫圖外面。
private void Form1_Load(object sender, System.EventArgs e)
{
//獲得pictureBox1的畫圖外面
Graphics g = this.pictureBox1.CreateGraphics();
}
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
//獲得pictureBox1的畫圖外面
Graphics g = e.Graphics;
}
//可以應用Graphics對象繪制出各類圖形圖案。控件的Paint事宜和OnPaint辦法都可以畫圖都是好機會。在OnPaint辦法裡繪制圖案必定從參數e外面獲得Graphics屬性。上面是兩個例子。
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.Clear(Color.White);
float x, y, w, h;
x = this.Left+2;
y = this.Top+2;
w = this.Width-4;
h = this.Height-4;
Pen pen = new Pen(Color.Red, 2);
e.Graphics.DrawRectangle(pen, x, y, w, h);
base.OnPaint (e);
}
private void PictureBoxII_Resize(object sender, EventArgs e)
{
this.Invalidate();
}
private void button1_Click(object sender, System.EventArgs e)
{
this.pictureBoxII1.CreateGraphics().FillEllipse(
Brushes.Blue, 10, 20, 50, 100);
}
//和文本有關的三個類:
//FontFamily——界說有著類似的根本設計但在情勢上有某些差別的一組字樣。沒法繼續此類。
//Font——界說特定的文本格局,包含字體、字號和字形屬性。沒法繼續此類。
//StringFormat——封裝文本結構信息(如對齊方法和行距),顯示操作(如省略號拔出和國度尺度 (National) 數字位調換)和 OpenType 功效。沒法繼續此類。
//上面的法式顯示了一段文字。
private void button2_Click(object sender, System.EventArgs e)
{
Graphics g = this.pictureBoxII1.CreateGraphics();
g.FillRectangle(Brushes.White, this.pictureBoxII1.ClientRectangle);
string s = "aaaaaaaaaaaaaaaaaaaaaaaaaa";
FontFamily fm = new FontFamily("ËÎÌå");
Font f = new Font(fm, 20, FontStyle.Bold, GraphicsUnit.Point);
RectangleF rectF = new RectangleF(30, 20, 180, 205);
StringFormat sf = new StringFormat();
SolidBrush sbrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));
sf.LineAlignment = StringAlignment.Center;
sf.FormatFlags = StringFormatFlags.DirectionVertical;
g.DrawString(s, f, sbrush, rectF, sf);
}
//GDI+的途徑——GraphicsPath類
//GraphicsPath類供給了一系列屬性和辦法,應用它可以獲得途徑上的症結點,可以添加直線段、圓等幾何元素。可以取得包抄矩形,停止拾取測試。這些功效都怎樣用,要細心看一下。
private void button3_Click(object sender, System.EventArgs e)
{
//畫圖外面
Graphics g = this.pictureBoxII1.CreateGraphics();
//填充成白色
g.FillRectangle(Brushes.White, this.ClientRectangle);
//弄一個畫圖途徑¶
GraphicsPath gp = new GraphicsPath();
//添加一些聚集圖形
gp.AddEllipse(20, 20, 300, 200);
gp.AddPie(50, 100, 300, 100, 45, 200);
gp.AddRectangle(new Rectangle(100, 30, 100, 80));
//在畫圖外面上繪制畫圖途徑
g.DrawPath(Pens.Blue, gp);
//平移
g.TranslateTransform(200, 20);
//填充畫圖途徑¶
g.FillPath(Brushes.GreenYellow, gp);
gp.Dispose();
}
//區域——Region類
//從已有的矩形和途徑可以創立Region。應用Graphics.FillRegion辦法繪制Region。該類指導由矩形和由途徑組成的圖形外形的外部。沒法繼續此類。
//突變色填充
//須要應用兩個刷子:
//線性梯度刷子(LinearGradientBrush)
//途徑梯度刷子(PathGuadientBrush)
private void button4_Click(object sender, System.EventArgs e)
{
//畫圖外面
Graphics g = this.pictureBoxII1.CreateGraphics();
g.FillRectangle(Brushes.White, this.pictureBoxII1.ClientRectangle);
//界說一個線性梯度刷子
LinearGradientBrush lgbrush =
new LinearGradientBrush(
new Point(0, 10),
new Point(150, 10),
Color.FromArgb(255, 0, 0),
Color.FromArgb(0, 255, 0));
Pen pen = new Pen(lgbrush);
//用線性筆刷梯度後果的筆繪制一條直線段並填充一個矩形
g.DrawLine(pen, 10, 130, 500, 130);
g.FillRectangle(lgbrush, 10, 150, 370, 30);
//界說途徑並添加一個橢圓
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(10, 10, 200, 100);
//用該途徑界說途徑梯度刷子
PathGradientBrush brush =
new PathGradientBrush(gp);
//色彩數組
Color[] colors = {
Color.FromArgb(255, 0, 0),
Color.FromArgb(100, 100, 100),
Color.FromArgb(0, 255, 0),
Color.FromArgb(0, 0, 255)};
//界說色彩突變比率
float[] r = {0.0f, 0.3f, 0.6f, 1.0f};
ColorBlend blend = new ColorBlend();
blend.Colors = colors;
blend.Positions = r;
brush.InterpolationColors = blend;
//在橢圓外填充一個矩形
g.FillRectangle(brush, 0, 0, 210, 110);
//用添加了橢圓的途徑界說第二個途徑梯度刷子
GraphicsPath gp2 = new GraphicsPath();
gp2.AddEllipse(300, 0, 200, 100);
PathGradientBrush brush2 = new PathGradientBrush(gp2);
//設置中間點地位和色彩
brush2.CenterPoint = new PointF(450, 50);
brush2.CenterColor = Color.FromArgb(0, 255, 0);
//設置界限色彩
Color[] color2 = {Color.FromArgb(255, 0, 0)};
brush2.SurroundColors = color2;
//用第二個梯度刷填充橢圓
g.FillEllipse(brush2, 300, 0, 200, 100);
}
//GDI+的坐標體系
//通用坐標系——用戶自界說坐標系。
//頁面坐標系——虛擬坐標系。
//裝備坐標系——屏幕坐標系。
//當頁面坐標系和裝備坐標系的單元都是象素時,它們雷同。
private void button10_Click(object sender, System.EventArgs e)
{
Graphics g = this.pictureBoxII1.CreateGraphics();
g.Clear(Color.White);
this.Draw(g);
}
private void Draw(Graphics g)
{
g.DrawLine(Pens.Black, 10, 10, 100, 100);
g.DrawEllipse(Pens.Black, 50, 50, 200, 100);
g.DrawArc(Pens.Black, 100, 10, 100, 100, 20, 160);
g.DrawRectangle(Pens.Green, 50, 200, 150, 100);
}
private void button5_Click(object sender, System.EventArgs e)
{
//左移
Graphics g = this.pictureBoxII1.CreateGraphics();
g.Clear(Color.White);
g.TranslateTransform(-50, 0);
this.Draw(g);
}
private void button6_Click(object sender, System.EventArgs e)
{
//右移
Graphics g = this.pictureBoxII1.CreateGraphics();
g.Clear(Color.White);
g.TranslateTransform(50, 0);
this.Draw(g);
}
private void button7_Click(object sender, System.EventArgs e)
{
//扭轉
Graphics g = this.pictureBoxII1.CreateGraphics();
g.Clear(Color.White);
g.RotateTransform(-30);
this.Draw(g);
}
private void button8_Click(object sender, System.EventArgs e)
{
//縮小
Graphics g = this.pictureBoxII1.CreateGraphics();
g.Clear(Color.White);
g.ScaleTransform(1.2f, 1.2f);
this.Draw(g);
}
private void button9_Click(object sender, System.EventArgs e)
{
//減少
Graphics g = this.pictureBoxII1.CreateGraphics();
g.Clear(Color.White);
g.ScaleTransform(0.8f, 0.8f);
this.Draw(g);
}
//全局坐標——變換關於畫圖外面上的每一個圖元都邑發生影響。平日用於設定通用坐標系。
//一下法式將原定挪動到控件中間,而且Y軸正向朝上。
//先畫一個圓
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
g.DrawEllipse(Pens.Black, -100, -100, 200, 200);
//使y軸正向朝上,必需做絕對於x軸鏡像
//變換矩陣為[1,0,0,-1,0,0]
Matrix mat = new Matrix(1, 0, 0, -1, 0, 0);
g.Transform = mat;
Rectangle rect = this.ClientRectangle;
int w = rect.Width;
int h = rect.Height;
g.TranslateTransform(w/2, -h/2);
//以原點為中間,做一個半徑為100的圓
g.DrawEllipse(Pens.Red, -100, -100, 200, 200);
g.TranslateTransform(100, 100);
g.DrawEllipse(Pens.Green, -100, -100, 200, 200);
g.ScaleTransform(2, 2);
g.DrawEllipse(Pens.Blue, -100, -100, 200, 200);
//部分坐標系——只對某些圖形停止變換,而其它圖形元素不變。
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
//客戶區設置為白色
g.FillRectangle(Brushes.White, this.ClientRectangle);
//y軸朝上
Matrix mat = new Matrix(1, 0, 0, -1, 0, 0);
g.Transform = mat;
//挪動坐標原點到窗體中間
Rectangle rect = this.ClientRectangle;
int w = rect.Width;
int h = rect.Height;
g.TranslateTransform(w/2, -h/2);
//在全局坐標下繪制橢圓
g.DrawEllipse(Pens.Red, -100, -100, 200, 200);
g.FillRectangle(Brushes.Black, -108, 0, 8, 8);
g.FillRectangle(Brushes.Black, 100, 0, 8, 8);
g.FillRectangle(Brushes.Black, 0, 100, 8, 8);
g.FillRectangle(Brushes.Black, 0, -108, 8, 8);
//創立一個橢圓然後在部分坐標系中停止變換
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(-100, -100, 200, 200);
Matrix mat2 = new Matrix();
//平移
mat2.Translate(150, 150);
//扭轉
mat2.Rotate(30);
gp.Transform(mat2);
g.DrawPath(Pens.Blue, gp);
PointF[] p = gp.PathPoints;
g.FillRectangle(Brushes.Black, p[0].X-2, p[0].Y+2, 4, 4);
g.FillRectangle(Brushes.Black, p[3].X-2, p[3].Y+2, 4, 4);
g.FillRectangle(Brushes.Black, p[6].X-4, p[6].Y-4, 4, 4);
g.FillRectangle(Brushes.Black, p[9].X-4, p[9].Y-4, 4, 4);
gp.Dispose();
//base.OnPaint (e);
}
//Alpha混雜
//Color.FromArgb()的A就是Alpha。Alpha的取值規模從0到255。0表現完整通明,255完整不通明。
//以後色=遠景色×alpha/255+配景色×(255-alpha)/255
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
//創立一個填充矩形
SolidBrush brush = new SolidBrush(Color.BlueViolet);
g.FillRectangle(brush, 180, 70, 200, 150);
//創立一個位圖,個中兩個位圖之間有通明後果
Bitmap bm1 = new Bitmap(200, 100);
Graphics bg1 = Graphics.FromImage(bm1);
SolidBrush redBrush =
new SolidBrush(Color.FromArgb(210, 255, 0, 0));
SolidBrush greenBrush =
new SolidBrush(Color.FromArgb(210, 0, 255, 0));
bg1.FillRectangle(redBrush, 0, 0, 150, 70);
bg1.FillRectangle(greenBrush, 30, 30, 150, 70);
g.DrawImage(bm1, 100, 100);
//創立一個位圖,個中兩個位圖之間沒有通明後果
Bitmap bm2 = new Bitmap(200, 100);
Graphics bg2 = Graphics.FromImage(bm2);
bg2.CompositingMode = CompositingMode.SourceCopy;
bg2.FillRectangle(redBrush, 0, 0, 150, 170);
bg2.FillRectangle(greenBrush, 30, 30, 150, 70);
g.CompositingQuality = CompositingQuality.GammaCorrected;
g.DrawImage(bm2, 300, 200);
//base.OnPaint (e);
}
//反走樣
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
//縮小8倍
g.ScaleTransform(8, 8);
//沒有反走樣的圖形和文字
Draw(g);
//設置反走樣
g.SmoothingMode = SmoothingMode.AntiAlias;
//右移40
g.TranslateTransform(40, 0);
//再繪制就是反走樣以後的了
Draw(g);
//base.OnPaint (e);
}
private void Draw(Graphics g)
{
//繪制圖形和文字
g.DrawLine(Pens.Gray, 10, 10, 40, 20);
g.DrawEllipse(Pens.Gray, 20, 20, 30, 10);
string s = "反走樣測試";
Font font = new Font("宋體", 5);
SolidBrush brush = new SolidBrush(Color.Gray);
g.DrawString(s, font, brush, 10, 40);
}
信任本文所述對年夜家的C#法式設計有必定的自創價值。