Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,873 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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();
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] ) ) );