void Initialize() { try { myappconfig = new MyAppConfig(); var offset = System.Configuration.ConfigurationManager.AppSettings.Get("offset"); myappconfig.DesktopLocation = (Point) new PointConverter().ConvertFromString(offset); var filename = System.Configuration.ConfigurationManager.AppSettings.Get("filename_img"); myappconfig.Filename = filename; } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } //myappconfig.ImageAlign = ContentAlignment.MiddleCenter; //myappconfig.Offset = Point.Empty; //1920/2 - 64/2==928 //1080/2 - 64/2==508 this.propertyGrid1.SelectedObject = myappconfig; try { frmCrosshair = new FormDesktopCrosshair(); var rect = Screen.PrimaryScreen.Bounds; frmCrosshair.Size = rect.Size; var b = new Binding("DesktopLocation", myappconfig, "DesktopLocation"); frmCrosshair.DataBindings.Add(b); //var offset = myappconfig.DesktopLocation; //(frmCrosshair as FormDesktopCrosshair).SetDesktopLocation(offset.X, offset.Y); var fs = new System.IO.FileStream(myappconfig.Filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite); //this.textBox1.Text = filename; streamImg = fs; var img = new Bitmap(streamImg); frmCrosshair.BackgroundImage = img; frmCrosshair.DataBindings.Add("Visible", myappconfig, "Visible", false, DataSourceUpdateMode.OnPropertyChanged); //this.checkBox1.DataBindings.Add("Checked", frmCrosshair, "Visible", false, DataSourceUpdateMode.OnPropertyChanged); this.checkBox1.DataBindings.Add("Checked", myappconfig, "Visible", false, DataSourceUpdateMode.OnPropertyChanged); frmCrosshair?.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
void CleanUp() { myappconfig = null; frmCrosshair?.Close(); frmCrosshair?.Dispose(); frmCrosshair = null; streamImg?.Close(); streamImg?.Dispose(); streamImg = null; }