Draw remote text on Picturebox

Marcelo Morais 21 Reputation points

I had used AccessibilityService to get location X and Y of elemet that is displayed on screen of my smartphone. Now i need draw this element (that is a text) on PictureBox, according with position that is showing on remote device (my smartphone).

This was tried, but without success:

public frmMain()  
        pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);  
    // ...  
    string[] tokens = item.SubItems[5].Text.Split('x'); // remote screen resolution (W x H), Eg: 1080x1920  
    var text = "text"; // element to draw on PictureBox   
    var x = 200; // position X of element on remote screen  
    var y = 170; // position Y of element on remote screen  
    using (Graphics g = Graphics.FromImage(pictureBox1.Image))  
        g.DrawString(text, new Font("Tahoma", 8), Brushes.Black, new Point((int.Parse(x) * int.Parse(tokens[0].ToString())) / pictureBox1.Width, (int.Parse(y) * int.Parse(tokens[1].ToString())) / pictureBox1.Height));  
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,825 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,226 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.1K Reputation points

    Check this modification:

    g.DrawString( text, new Font( "Tahoma", 8 ), Brushes.Black,   
        new Point(   
            int.Parse( x ) * pictureBox1.Width / int.Parse( tokens[0] ),   
            int.Parse( y ) * pictureBox1.Height / int.Parse( tokens[1] ) ) );  
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful