{
Brush brush = new LinearGradientBrush(rect, begin, end, LinearGradientMode.Horizontal);
private void DrawLoading(Control ctl, string sText)
{
Font font = new Font("楷体_GB2312", 16);
Graphics g = ctl.CreateGraphics();
//g.SmoothingMode = SmoothingMode.AntiAlias;
//消除锯齿
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
//设置文本对齐方式
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Near;
//以父控件背景色清空内容
g.Clear(ctl.Parent.BackColor);
g.DrawString(sText, font, new SolidBrush(Color.Black), ctl.ClientRectangle, format);
//释放GDI+资源
font.Dispose();
g.Dispose();
}
一个重要的方法:Color.FromArgb(Alapha,Color),作用试过就知。
你应该看一下MeasureCharacterRanges的用法,比如:
public void MeasureCharacterRangesRegions(PaintEventArgs e)
{
// Set up string.
string measureString = "First and Second ranges";
Font stringFont = new Font("Times New Roman", 16.0F);
// Set character ranges to "First" and "Second".
CharacterRange characterRanges = { new CharacterRange(0, 5), new CharacterRange(10, 6) };
// Create rectangle for layout.
float x = 50.0F;
float y = 50.0F;
float width = 35.0F;
float height = 200.0F;
RectangleF layoutRect = new RectangleF(x, y, width, height);
// Set string format.
StringFormat stringFormat = new StringFormat();
stringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
stringFormat.SetMeasurableCharacterRanges(characterRanges); 常用代码(GDI+)
// Draw string to screen.
e.Graphics.DrawString(measureString, stringFont, Brushes.Black, x, y, stringFormat);
// Measure two ranges in string.
Region stringRegions = new Region;
stringRegions = e.Graphics.MeasureCharacterRanges(measureString, stringFont, layoutRect, stringFormat);
// Draw rectangle for first measured range.
RectangleF measureRect1 = stringRegions.GetBounds(e.Graphics);
e.Graphics.DrawRectangle(new Pen(Color.Red, 1), Rectangle.Round(measureRect1));
// Draw rectangle for second measured range.
RectangleF measureRect2 = stringRegions.GetBounds(e.Graphics);
e.Graphics.DrawRectangle(new Pen(Color.Blue, 1), Rectangle.Round(measureRect2));
}
Dim H As New Bitmap(300, 300)
Dim G As Graphics = Graphics.FromImage(H)
G.Clear(Color.White)
Dim C As New System.Drawing.Drawing2D.ColorBlend
C.Colors() = New Color() {Color.Red, Color.Yellow, Color.Blue}
C.Positions() = New Single() {0.0, 0.5, 1.0}
Dim G_Brush As System.Drawing.Drawing2D.LinearGradientBrush
G_Brush = New System.Drawing.Drawing2D.LinearGradientBrush(New Rectangle(0, 0, 300, 300), Color.Red, Color.Black, Drawing2D.LinearGradientMode.BackwardDiagonal)
G_Brush.InterpolationColors() = C
G.FillRectangle(G_Brush, 0, 0, 300, 300)
G.Dispose()
Me.BackgroundImage = H
dim graph as graphics
dim rectsquare as rectangle
dim graphpath as drawing2d.graphicspath
dim brushsquare as drawing2d.pathgradientbrush
graph=graphics.fromhwnd(picsource.handle)
graphpath=new drawing2d.graphicspath()
rectsquare=new rectangle(10,20,23,27)
graphpath.addrectangle(rectsquare)
brushsquare=new drawing2d.pathgradientbrush(graphpath)
brushsquare.centercolor=color.fromargb(255,0,255,0)
brushsquare.surroundcolors=color.fromargb(255,0,0,255)
常用代码(GDI+)graph.fillpath(brushsquare,graphpath)