need help for drawing strings randomly on form

Metric

Member
Joined
Feb 24, 2005
Messages
5
Programming Experience
1-3
Hi,
I am developing an application which will display random strings from a text file
on a form using system.drawing..
I want to allow the user to choose how often and how long a string will be displayed. ie.; message should be drawn every n seconds and should be removed(refreshed) after m seconds.
plse help me..
 
Have a look at these classes:
-System.Random
-System.Drawing.Graphics (and it's DrawString method)
-System.Windows.Forms.Timer (and it's Tick event)
-System.Threading.Thread (and it's Sleep method)
-System.IO.StringReader
 
Hi ,
thanks a lot for the hints.
now i am able to draw the strings as required.

i have one more doubt. i am drawing the string on invisible form.ie; back color and transparency key as same (white) and boarderstyle as none .
i am able to display it but the edges of the string is having a white color.
if i change the backcolor and transparency key from white to some other color, then that color is coming on the edges of the string.
if opacity is set to zero then the form including the drawn string is becoming invisible.
pleasae help me to draw ste string with one color.
i am sending the piece of code which i am using to drw the string.

Dim grfx As Graphics = CreateGraphics()
Public drawstring as string = "Some String"
Public drawBrush AsNew SolidBrush(Color.Black)
Public drawFont AsNew Font("Arial", 38)
grfx.DrawString(draString, drawFont, drawBrush, x, y)
grfx.Dispose()

metric

 
Last edited:
If your string is always black, change the BackColor and TransparencyKey to just a shade away from black. something like:
VB.NET:
BackColor = Color.FromArgb(0, 0, 1)
If the strings may change color, what I've done in the past is to create a procedure that takes the string color and alters it just a shade so that it's very similar, then set the BackColor and TransparencyKey to that new color.
Also note that there is no need to create a SolidBrush of color black. There is one already available for use in the System.Drawing namespace. Change your drawstring code to this:
VB.NET:
grfx.DrawString(draString, drawFont, Brushes.Black, x, y)
Create a SolidBrush if you need a color that is not provided by the Brushes or SystemBrushes classes. Also be sure to dispose of the Brush if you do create one.
 
Last edited:
thank you
i tried the way u told.
now it is working fine. can u tell me how to set color system.drawing.brushes dynamically. i want change the color of the brush from color dialog.

i have one more problem
The application is working fine with windows xp. when tried it on other system
(windows me), form is becoming visible. ie; color of the form becomes what ever color i had given as back color. i had set the back color and transpaency key as same but still it is showing the back color. i tried by changing the opacity to zero but in that case form and the string are becoming in visble.
 
To set the colors dynamically from a ColorDialog, use the value of the ColorDialog along with the SolidBrush as you did in your first code.
I've never used Windows ME and don't know anyhting about it, so I can't help with that problem.
As far as changing the opacity to zero: the reason the form and string become invisible is that you are drawing on the form. If you set the opacity to zero, any graphics on the form will become invisible.
 
Back
Top