Format color for text of RTB as color blend effect of YIM ??

sinbad911

Member
Joined
Jan 31, 2006
Messages
13
Programming Experience
Beginner
i want to format color for text of RTB as color blend effect of YIM
can u help me?
colorblend1.gif
 
I suppose it should be an easy task. Take a look at the code below as well as at the attached project.

VB.NET:
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Button1_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] Button1.Click
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] G [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Graphics
G = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].CreateGraphics
G.Clear([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].BackColor)
G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] largeFont [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Font("Tahoma", 48, FontStyle.Bold, GraphicsUnit.Point)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] gradientStart [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] PointF(0, 0)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] txt [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "Gradient Text"
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] txtSize [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SizeF
txtSize = G.MeasureString(txt, largeFont)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] gradientEnd [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] PointF
gradientEnd.X = txtSize.Width
gradientEnd.Y = txtSize.Height
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] grBrush [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] LinearGradientBrush(gradientStart, gradientEnd, Color.Yellow, Color.Blue)
G.DrawString(txt, largeFont, grBrush, 10, 30)
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]

HTH
Regards ;)

Kulrom :D
 

Attachments

  • GradientText.zip
    21.5 KB · Views: 28
kulrom said:
I suppose it should be an easy task. Take a look at the code below as well as at the attached project.

VB.NET:
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Button1_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] Button1.Click
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] G [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Graphics
G = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].CreateGraphics
G.Clear([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].BackColor)
G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] largeFont [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Font("Tahoma", 48, FontStyle.Bold, GraphicsUnit.Point)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] gradientStart [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] PointF(0, 0)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] txt [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "Gradient Text"
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] txtSize [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SizeF
txtSize = G.MeasureString(txt, largeFont)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] gradientEnd [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] PointF
gradientEnd.X = txtSize.Width
gradientEnd.Y = txtSize.Height
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] grBrush [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] LinearGradientBrush(gradientStart, gradientEnd, Color.Yellow, Color.Blue)
G.DrawString(txt, largeFont, grBrush, 10, 30)
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]

HTH
Regards ;)

Kulrom :D

thanks for your code
but i need the code that can format color for RTB and i can add more than 2 color (like YIM)
do u understand?

.............................:eek:
 
For multiple colors, you would need to draw multiple gradient brushes... from one color to the next... then from that color to the next.... and so on until all colors have been cycled. You will also need to do some minor calculations to determine start and end points for each band....

-tg
 
Found in the System.Drawing.Drawing2D namespace is the PathGradientBrush. Use it's InterpolationBlend Property with an instance of the ColorBlend class. This will provide multicolor linear gradients. The ColorBlend class contains two parallel arrays of colors and positions, add as many colors you want and specify in percent the positions for the transitions.

I don't think you can use it to color the text in the RichTextBox, but you can display a graphical preview of the text with blended colors.

MSDN ref PathGradientBrush.InterpolationColors Property
 
JohnH said:
Found in the System.Drawing.Drawing2D namespace is the PathGradientBrush. Use it's InterpolationBlend Property with an instance of the ColorBlend class. This will provide multicolor linear gradients. The ColorBlend class contains two parallel arrays of colors and positions, add as many colors you want and specify in percent the positions for the transitions.

I don't think you can use it to color the text in the RichTextBox, but you can display a graphical preview of the text with blended colors.

MSDN ref http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDrawingDrawing2DPathGradientBrushClassInterpolationColorsTopic.asp

colorblend2.gif

i try to write it like this
 
Back
Top