I was wondering is there any way to put my e.Graphics.DrawString() method into a variable(object) so that i can do some actions aftewards. The thing is that I ve got my words falling and rotating on the form. I ve also got a object wich is a Image which moves right or left. The problem is that i have to collect this words (falling and rotating) with my image object which i m able to move. I Know that the problem would have been much easier if i decided to populate images of string let s say into an array because i would have actual objects, but is there anyway to do that with the drawstring() already? I hope that i was clear enough.

Recommended Answers

All 5 Replies

Can you provide an example of what you're doing in code? I don't quite understand you.

  private void Form1_Paint(object sender, PaintEventArgs e)
        {



                RotateImage( "A", MainArray[0],ycoordinates[0]);
                RotateImage( "B", MainArray[1],ycoordinates[1]);

                // intersecting (strings  with another object)

               }



        public void RotateImage(string theString, int x, int y)  // method 0, main method
        {


            Graphics paper = CreateGraphics();

            paper.TranslateTransform(x, y);
            sz = paper.MeasureString(theString, stringFont);
            paper.RotateTransform(rtangle);
            rtangle += 10;
           paper.DrawString(theString, stringFont, new SolidBrush(Color.Blue), -(float)sz.Width / 2, -(float)sz.Height / 2);


        }

so i want my strings to intersect with this object once they reach a certain point when falling down

I suggest you create an object that records coordinates and rotation. Inside that object let it have its own drawstring method that calls the Graphics.DrawString method. That way you can keep track of it. Not sure there is any other way to do it and methods themselves cannot be objects.

Yeah i tought of that. I think i ll make a class with some properties(coordinates) and the drawstring method that you mentioned. I know that you can not cast methods to objects but still i was thinking if there is another way to do that i was thinking all night about that but couldn t get any idea. When i solve My problem i ll post the code here and mark this thread as solved! TNX!

Posting again here i m done with this so i will mark this trhead as solved.
I created a class for my object wich pick s up letters and i ve created a class for my letters and the thing that solved the main problem were the properties where i checked if there is a collision. I hate object oriented programming at first but now i love it and i can see how powerfull it actually is.
I m posting just a few lines of code.

for (int i = 0; i < lt.Y1.Length; i++) 
            {
                lt.Y1[i]++;
            }
             for (int i = 0; i < lt.X1.Length; i++)
             {
                 if ((lt.Y1[i] == cl.Y2) && ((lt.X1[i] >= cl.X2) && lt.X1[i] <= (cl.X2 + cl.Widht)))// for x coordinates if letter is between the the borders of the image then...
                 {
                     label6.Text = label6.Text + lt.Word[i];
                     lt.Y1[i] = // random coordinates;
                 }
             }        
             this.Invalidate();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.