Draw remote text on Picturebox

Marcelo Morais 21 Reputation points
2022-08-18T02:56:00.35+00:00

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()  
    {  
        InitializeComponent();  
        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));  
    }  
  
    pictureBox1.Invalidate();  
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,873 questions
C#
C#
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,648 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114.7K Reputation points
    2022-08-18T05:33:00.697+00:00

    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