12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System;
- using System.Drawing;
- using System.IO;
- using System.Net.Http;
- using System.Windows.Forms;
- namespace ScreenExtenderClient
- {
- public partial class SxdCliMainForm : Form
- {
- private Image _image;
- private Exception _lastException;
- public SxdCliMainForm()
- {
- InitializeComponent();
- if (Program.Args.Count > 1) SxdClVwPanel.Text = Program.Args[1];
- }
- private void UpdateTimer_Tick(object sender, EventArgs e)
- {
- var old = _image;
- try
- {
- var cl = new HttpClient();
- var httpResponseMessage = cl.GetAsync(Program.Args[0]).Result;
- var bytes = httpResponseMessage.Content.ReadAsByteArrayAsync().Result;
- var ms = new MemoryStream(bytes);
- _image = Image.FromStream(ms);
- _lastException = null;
- }
- catch (Exception exception)
- {
- _lastException = exception;
- Console.WriteLine(exception);
- _image = null;
- }
- old?.Dispose();
- SxdClVwPanel.Invalidate();
- }
- private void SxdClVwPanel_Paint(object sender, PaintEventArgs e)
- {
- e.Graphics.Clear(BackColor);
- if (_image != null) e.Graphics.DrawImage(_image, Point.Empty);
- if (_lastException != null) ControlPaint.DrawStringDisabled(e.Graphics, _lastException.ToString(), Font, ForeColor, new Rectangle(0, 0, SxdClVwPanel.Width, SxdClVwPanel.Height), new StringFormat());
- }
- }
- }
|