public WidgetDetails CaptureWidget(object owner, string uniqueKey, string description, Rectangle bounds) { ModuleProc PROC = new ModuleProc("HomeScreenWidgets", "LoadItems"); WidgetDetails details = null; try { Form ownerForm = owner as Form; string getTypeHash = owner.GetType().ToString().ToLower().GetHashCode().ToString(); string uniquekeyHash = uniqueKey.ToLower().GetHashCode().ToString(); string fileName = "F_" + getTypeHash + "_" + uniquekeyHash + ".png"; string actualFileName = this.GetFilePattern(fileName); using (IsolatedStorageFileStream stream = this.GetStream(actualFileName, FileMode.Create, FileAccess.Write)) { if (_widgetsSchema.ContainsKey(fileName)) { details = _widgetsSchema[fileName]; } else { details = new WidgetDetails() { FileName = fileName, UniqueKey = uniqueKey }; _widgetsSchema.Add(fileName, details); } details.Description = !description.IsEmpty() ? description : Path.GetFileName(fileName); this.SaveSchemaDetails(); if (ownerForm != null) { Extensions.SaveScreenshotToStream(ownerForm, stream); } else { Extensions.SaveScreenshotToStream(bounds, stream); } } } catch (Exception ex) { Log.Exception(PROC, ex); } finally { this.LoadWidgets(); } return(details); }
void OnWidget_Click(object sender, EventArgs e) { ModuleProc PROC = new ModuleProc("HomeScreenWidgets", "OnWidget_Click"); try { PreviewWidget widget = sender as PreviewWidget; WidgetDetails widgetDetails = widget.Tag as WidgetDetails; this.OnWidgetClick(widgetDetails); } catch (Exception ex) { Log.Exception(PROC, ex); } }
private void OnWidgetClick(WidgetDetails widget) { ModuleProc PROC = new ModuleProc("HomeScreenWidgets", "OnWidgetLoad"); try { if (this.WidgetClick != null) { this.WidgetClick(this, new WidgetEventArgs(widget)); } } catch (Exception ex) { Log.Exception(PROC, ex); } }
private void LoadImage(string fileName) { ModuleProc PROC = new ModuleProc("HomeScreenWidgets", "LoadImage"); WidgetDetails widgetDetails = null; try { string actualFileName = this.GetFilePattern(fileName); using (Stream st = new IsolatedStorageFileStream(actualFileName, FileMode.Open, FileAccess.Read, _storage)) { string text = Path.GetFileNameWithoutExtension(fileName); if (_widgetsSchema.ContainsKey(fileName)) { widgetDetails = _widgetsSchema[fileName]; text = widgetDetails.Description; PreviewWidget wid = new PreviewWidget(this.WidgetWidth, this.WidgetHeight, new Bitmap(st), false); wid.Text = text; wid.BorderColor = this.BorderColor; wid.BorderColorHover = this.BorderColorHover; wid.ForeColor = Color.Black; wid.Margin = new Padding(3); wid.Tag = widgetDetails; wid.Cursor = Cursors.Hand; wid.Click += new EventHandler(OnWidget_Click); wid.CloseClick += new EventHandler(OnWidget_CloseClick); _container.Controls.Add(wid); } } } catch (Exception ex) { Log.Exception(PROC, ex); } finally { if (widgetDetails != null) { this.OnWidgetLoad(_widgetsSchema[fileName]); } } }
void OnWidget_CloseClick(object sender, EventArgs e) { ModuleProc PROC = new ModuleProc("HomeScreenWidgets", "OnWidget_Click"); try { PreviewWidget widget = sender as PreviewWidget; WidgetDetails widgetDetails = widget.Tag as WidgetDetails; widget.CloseClick -= this.OnWidget_CloseClick; _storage.DeleteFile(this.GetFilePattern(widgetDetails.FileName)); } catch (Exception ex) { Log.Exception(PROC, ex); } finally { this.LoadWidgets(); } }