private void SubscribeEvent() { SubscriptionToken resourceAddedEventToken = _eventAggregator.GetEvent <ResourceAddedEvent>().Subscribe((e) => { _listBoxController.Add(_resourceService.GetImageResource(e.Name)); }); SubscriptionToken resourceUpdatedEventToken = _eventAggregator.GetEvent <ResourceUpdatedEvent>().Subscribe((e) => { ImageResourceInfo imageResourceInfo = _listBoxController.Find <ImageResourceInfo>((resource) => { return(resource.Name == e.Name); }); if (imageResourceInfo != null) { _listBoxController.Replace(imageResourceInfo, _resourceService.GetImageResource(e.Name)); } }); SubscriptionToken resourceRemovedEventToken = _eventAggregator.GetEvent <ResourceRemovedEvent>().Subscribe((e) => { ImageResourceInfo imageResourceInfo = _listBoxController.Find <ImageResourceInfo>((resource) => { return(resource.Name == e.Name); }); _listBoxController.Remove(imageResourceInfo); }); this.Disposed += (sender, e) => { _eventAggregator.GetEvent <ResourceAddedEvent>().Unsubscribe(resourceAddedEventToken); _eventAggregator.GetEvent <ResourceUpdatedEvent>().Unsubscribe(resourceUpdatedEventToken); _eventAggregator.GetEvent <ResourceRemovedEvent>().Unsubscribe(resourceRemovedEventToken); }; }
public void UpdateView() { this.ViewUpdating = true; ShellControlHelper.PropertyDescriptorUpdate(this, this._entity); FormElementPictureBoxEntityDev entity = (FormElementPictureBoxEntityDev)_formElement; PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(this); PropertyDescriptor pds; pds = pdc.Find("Image", false); if (pds != null) { if (String.IsNullOrEmpty(entity.Img) == false) { ImageResourceInfo imageResource = _resourceComponentService.GetImageResource(entity.Img); if (imageResource != null) { Image image = imageResource.GetImage(); pds.SetValue(this, image); } } else { pds.SetValue(this, null); } } ShellControlHelper.SetProperty(this, "SizeMode", entity.SizeMode); this.ViewUpdating = false; }
/// <summary> /// /// </summary> /// <param name="info"></param> /// <returns></returns> public long InsertInfo(ImageResourceInfo info) { ///图片名称不允许重复 int cnt = dal.GetCounts("[IMAGE_NAME] = N'" + info.ImageName + "'"); if (cnt > 0) { throw new Exception("MC:0x00000007"); ///图片名称不允许重复 } ///相同图片类型的图片描述不允许重复 cnt = dal.GetCounts("[IMAGE_NAME_CN] = N'" + info.ImageNameCn + "' and [IMAGE_TYPE] = " + info.ImageType.GetValueOrDefault() + ""); if (cnt > 0) { throw new Exception("MC:0x00000010"); ///相同图片类型的图片描述不允许重复 } cnt = dal.GetCounts("[IMAGE_NAME_EN] = N'" + info.ImageNameEn + "' and [IMAGE_TYPE] = " + info.ImageType.GetValueOrDefault() + ""); if (cnt > 0) { throw new Exception("MC:0x00000010"); ///相同图片类型的图片描述不允许重复 } ///样式名称不允许重复 cnt = dal.GetCounts("[CSS_TAG_NAME] = N'" + info.CssTagName + "'"); if (cnt > 0) { throw new Exception("MC:0x00000012"); ///样式名称不允许重复 } return(dal.Add(info)); }
public ImageListViewController(ImageListView imageListView) { _imageListView = imageListView; _imageListView.AllowDrop = false; _imageListView.AllowMultiSelection = true; _getImage = new ImageListViewItem.GetImageHandler((key) => { ImageResourceInfo resourceInfo = (ImageResourceInfo)key; return(resourceInfo.GetImage()); }); }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); graphics.FillRectangle(Brushes.White, cellBounds.X + 1, cellBounds.Y + 1, cellBounds.Width - 2, cellBounds.Height - 2); int imageLocationX = cellBounds.X + 2; int imageLocationY = cellBounds.Y + 2; int imageSizeW = 16; int imageSizeH = 16; Rectangle imageBounds = new Rectangle(imageLocationX, imageLocationY, imageSizeW, imageSizeH); int textLocationX = imageLocationX + imageSizeW + 2; int textLocationY = cellBounds.Y + 4; Point textLoation = new Point(textLocationX, textLocationY); if (this.Value != null && this.Value.ToString() != String.Empty) { string resourceName = this.Value.ToString(); Image imageDraw; if (_resourceService.Container(resourceName)) { ImageResourceInfo imageResource = _resourceService.GetImageResource(resourceName); Image image = imageResource.GetImage(); imageDraw = DrawingTool.GetScaleImage(image, imageSizeW, imageSizeH); if (image != imageDraw) { image.Dispose(); } } else { imageDraw = DrawingTool.Mark.FileNotFind(imageBounds.Size); } try { graphics.DrawImage(imageDraw, imageBounds); } catch (Exception exception) { Debug.Assert(false, exception.Message); imageDraw = DrawingTool.Mark.FileNotFind(imageBounds.Size); graphics.DrawImage(imageDraw, imageBounds); } imageDraw.Dispose(); Font font = new Font(cellStyle.Font, cellStyle.Font.Style | FontStyle.Bold); Brush textBrush = new SolidBrush(cellStyle.ForeColor); graphics.DrawString(resourceName, font, textBrush, textLoation); font.Dispose(); textBrush.Dispose(); } }
public void Remove(string resourceName) { for (int i = 0; i < _imageListView.Items.Count; i++) { ImageResourceInfo imageResource = (ImageResourceInfo)_imageListView.Items[i].Key; if (imageResource.Name.Equals(resourceName)) { _imageListView.Items.RemoveAt(i); break; } } }
public static bool ImageResourceChoose(out ImageResourceInfo imageResource) { bool result = false; imageResource = null; using (ImageResourceChooseView view = new ImageResourceChooseView()) { if (view.ShowDialog() == System.Windows.Forms.DialogResult.OK) { imageResource = view.SelectedImageResource; result = true; } } return(result); }
private void _listBoxController_SelectedItemChanged(object sender, EventArgs e) { _selectedImageResource = _listBoxController.GetSelectedItem <ImageResourceInfo>(); if (_selectedImageResource == null) { if (this.pictureBoxPreview.Image != null) { this.pictureBoxPreview.Image = null; } return; } if (_imageCache.Keys.Contains(_selectedImageResource) == false) { Image thumbnailImage = DrawingTool.GetAutoScaleThumbnailImage( _selectedImageResource.GetImage(), this.pictureBoxPreview.Width, this.pictureBoxPreview.Height); _imageCache.Add(_selectedImageResource, thumbnailImage); } this.pictureBoxPreview.Image = _imageCache[_selectedImageResource]; }
public void Update(ImageResourceInfo imageResource) { Remove(imageResource.Name); Add(imageResource); }
public void Add(ImageResourceInfo imageResource) { ImageListViewItem item = new ImageListViewItem(imageResource, imageResource.Name, _getImage); _imageListView.Items.Add(item); }