Hi,
Am doing the imaging application. Here i was done the drawing a text on picturebix. It is working fine.
Now i need to select that text and modify the size and color. And also i have move the text througout the picturebox.
Am working on that, but am not able to find the solution.
Can anyone please tell me how to do this.
Below is the code for draw the text
public void InsertText(string text, int xPosition, int yPosition, string fontname, float fontsize, string fontstyle, string colorname)
{
Bitmap temp = (Bitmap)bmp;
Bitmap bmap = (Bitmap)temp.Clone();
Graphics gr = Graphics.FromImage(bmap);
if (string.IsNullOrEmpty(fontname))
fontname = "Times New Roman";
if (fontsize.Equals(null))
fontsize = 10.0F;
Font font = new Font(fontname, fontsize);
if (!string.IsNullOrEmpty(fontstyle))
{
FontStyle fstyle = FontStyle.Regular;
switch (fontstyle.ToLower())
{
case "bold":
fstyle = FontStyle.Bold;
break;
case "italic":
fstyle = FontStyle.Italic;
break;
case "underline":
fstyle = FontStyle.Underline;
break;
case "strikeout":
fstyle = FontStyle.Strikeout;
break;
}
font = new Font(fontname, fontsize, fstyle);
}
if (string.IsNullOrEmpty(colorname))
colorname = "Black";
Color color1 = Color.FromName(colorname);
int gW = (int)(text.Length * fontsize);
gW = gW == 0 ? 10 : gW;
LinearGradientBrush LGBrush = new LinearGradientBrush(new Rectangle(0, 0, gW, (int)fontsize), color1, color1, LinearGradientMode.Vertical);
//lbltext.Visible = true;
//lbltext.ForeColor = color1;
//lbltext.Location = new Point(xPosition, yPosition);
//lbltext.Text = text;
//gr.DrawString(text, font, Brushes.White, new PointF(xPos, yPos));
gr.DrawString(text, font, LGBrush, new PointF(xPosition, yPosition));
temp = (Bitmap)bmap.Clone();
pictureBox1.Image = temp;
}
}
Loading

FroglegPosted Jun 14, 2011, 4:54 AM
Whoops it done with vs2010 - let me know if you have problems opening it
Farooque AliPosted Jun 14, 2011, 3:14 AM
Mycode is working fine. But i have move that text using mouse throughout the picture box. And if i select the text it should be selected and display the font size and color dialog box to change it appearance.
Hope you understand my description
Posted Jun 14, 2011, 3:08 AM
Bitmap temp = (Bitmap) pictureBox1.Image ;
And it is working... ? Are you getting any error ?