private void handpcbx_DragDrop(object sender, DragEventArgs e) { Handpcbx pbx = sender as Handpcbx; String lastboxType = lastbox.GetType().Name; Card replacement; if (lastboxType.Equals("Handpcbx")) { Handpcbx lastbox2 = lastbox as Handpcbx; replacement = lastbox2.getCard(); lastbox2.setCard(pbx.getCard()); pbx.setCard(replacement); lastbox2.updateImage(); pbx.updateImage(); } else if (lastboxType.Equals("Stagepcbx")) { Stagepcbx lastbox2 = lastbox as Stagepcbx; replacement = lastbox2.getCard(); lastbox2.setCard(pbx.getCard()); pbx.setCard(replacement); lastbox2.updateImage(); pbx.updateImage(); } else { throw new Exception("Not implemented"); } }
private static void Animate(PictureBox box, bool enable) { var anim = box.GetType().GetMethod("Animate", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(bool) }, null); anim.Invoke(box, new object[] { enable }); }
// Create the event when clicking the late reservation panel... private void OpenLateReservation(object sender, EventArgs e) { Panel pnl = new Panel(); Label lbl = new Label(); PictureBox picbox = new PictureBox(); int ReservId; if (sender.GetType() == pnl.GetType()) { Panel clicked = sender as Panel; ReservId = Convert.ToInt32(clicked.Name); StopReservation form = new StopReservation(this, User, ReservId); form.ShowDialog(); } if (sender.GetType() == lbl.GetType()) { Label clicked = sender as Label; ReservId = Convert.ToInt32(clicked.Name); StopReservation form = new StopReservation(this, User, ReservId); form.ShowDialog(); } if (sender.GetType() == picbox.GetType()) { PictureBox clicked = sender as PictureBox; ReservId = Convert.ToInt32(clicked.Name); StopReservation form = new StopReservation(this, User, ReservId); form.ShowDialog(); } }
private static bool IsAnimating(PictureBox box) { var fi = box.GetType().GetField("currentlyAnimating", BindingFlags.NonPublic | BindingFlags.Instance); return((bool)fi.GetValue(box)); }
/// <summary> /// 启用控件的双缓冲支持 /// </summary> /// <param name="pictureBox"></param> public static void EnableDoubleBuffered(this PictureBox pictureBox) { pictureBox.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) .SetValue(pictureBox, true, null); }
public PictureBoxTransform(PictureBox pb) { _pictureBox = pb; // http://stackoverflow.com/questions/3307271/how-to-get-the-value-of-non-public-members-of-picturebox _imgRectProperty = _pictureBox.GetType().GetProperty( "ImageRectangle", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); }
private Rectangle GetPictureBoxZoomSize(PictureBox p_PictureBox) { if (p_PictureBox != null) { System.Reflection.PropertyInfo _ImageRectanglePropert = p_PictureBox.GetType().GetProperty("ImageRectangle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); return((System.Drawing.Rectangle)_ImageRectanglePropert.GetValue(p_PictureBox, null)); } return(new System.Drawing.Rectangle(0, 0, 0, 0)); }
public Rectangle GetPictureDisplaySize(PictureBox pbxImage) { if (pbxImage != null) { PropertyInfo ppiImageRect = pbxImage.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic); return((Rectangle)ppiImageRect.GetValue(pbxImage, null)); } return(new Rectangle(0, 0, 1, 1)); }
/// <summary> /// 获取PictureBox在Zoom下显示的位置和大小 /// https://blog.csdn.net/zgke/article/details/4372246 /// </summary> /// <param name="p_PictureBox">Picture 如果没有图形或则非ZOOM模式 返回的是PictureBox的大小</param> /// <returns>如果p_PictureBox为null 返回 Rectangle(0, 0, 0, 0)</returns> private Rectangle GetPictureBoxZoomSize(PictureBox p_PictureBox) { if (p_PictureBox != null) { PropertyInfo _ImageRectanglePropert = p_PictureBox.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic); return((Rectangle)_ImageRectanglePropert.GetValue(p_PictureBox, null)); } return(new Rectangle(0, 0, 0, 0)); }
private Rectangle getPictureBoxOffset(PictureBox pb) { // It seems the only way of correctly adjusting for the picturebox position after it has been resized is to access private data from the picturebox class System.Reflection.PropertyInfo pInfo = pb.GetType().GetProperty("ImageRectangle", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); return((Rectangle)pInfo.GetValue(pb, null)); }
//实现锚点缩放(以鼠标所指位置为中心缩放); //步骤: //①先改picturebox长宽,长宽改变量一样; //②获取缩放后picturebox中实际显示图像的长宽,这里长宽是不一样的; //③将picturebox的长宽设置为显示图像的长宽; //④补偿picturebox因缩放产生的位移,实现锚点缩放。 // 注释:为啥要②③步?由于zoom模式的机制,把picturebox背景设为黑就知道为啥了。 //这里需要获取zoom模式下picturebox所显示图像的大小信息,添加 using System.Reflection; //pictureBox_MouseWheel事件没找到。。。手动添加,别忘在Form1.Designer.cs的“Windows 窗体设计器生成的代码”里加入: //this.pictureBox.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseWheel)。 private void pictureBox_MouseWheel(object sender, MouseEventArgs e) { PictureBox pictureBox = sender as PictureBox; int x = e.Location.X; int y = e.Location.Y; int ow = pictureBox.Width; int oh = pictureBox.Height; int VX, VY; //因缩放产生的位移矢量 if (e.Delta > 0) //放大 { //第①步 pictureBox.Width += zoomStep; pictureBox.Height += zoomStep; //第②步 PropertyInfo pInfo = pictureBox.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic); Rectangle rect = (Rectangle)pInfo.GetValue(pictureBox, null); //第③步 pictureBox.Width = rect.Width; pictureBox.Height = rect.Height; } if (e.Delta < 0) //缩小 { //防止一直缩成负值 if (pictureBox.Width < myBmp.Width) { return; } pictureBox.Width -= zoomStep; pictureBox.Height -= zoomStep; PropertyInfo pInfo = pictureBox.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic); Rectangle rect = (Rectangle)pInfo.GetValue(pictureBox, null); pictureBox.Width = rect.Width; pictureBox.Height = rect.Height; } //第④步,求因缩放产生的位移,进行补偿,实现锚点缩放的效果 VX = (int)((double)x * (ow - pictureBox.Width) / ow); VY = (int)((double)y * (oh - pictureBox.Height) / oh); pictureBox.Location = new Point(pictureBox.Location.X + VX, pictureBox.Location.Y + VY); }
private void GenerateCards() { YourScore.Show(); YourScore.Text = "Your Score: 0"; OpponentsScore.Show(); OpponentsScore.Text = "Opponent's Score: 0"; _opponentPic = new PictureBox { Name = "Opponent's Card", Image = Resources.card_back_blue, Location = new Point(Width - 125, 10), Size = new Size(100, 114), SizeMode = PictureBoxSizeMode.StretchImage }; Controls.Add(_opponentPic); Point nextLocation = new Point(10, 134); for (int i = 0; i < 10; i++) { PictureBox currentPic = new PictureBox { Name = "picDynamic" + i, Image = Resources.card_back_red, Location = nextLocation, Size = new Size(100, 114), SizeMode = PictureBoxSizeMode.StretchImage }; currentPic.Click += (sender, e) => { if (!string.IsNullOrEmpty(_drawnCard)) { return; } // Generate a random card _drawnCard = RandomCard(); currentPic.Name = _drawnCard; currentPic.Image = (Image)Resources.ResourceManager.GetObject(FileNameByCard(currentPic.Name)); _amountOfOpenedCards++; // Send the Generated card BeginSend("1" + currentPic.Name); // Receive an answer BeginRead(); // Remove click event handler FieldInfo currentPicFieldInfo = typeof(Control).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic); object obj = currentPicFieldInfo?.GetValue(currentPic); PropertyInfo currentPicPropertyInfo = currentPic.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance); EventHandlerList list = (EventHandlerList)currentPicPropertyInfo?.GetValue(currentPic, null); list?.RemoveHandler(obj, list[obj]); }; Controls.Add(currentPic); nextLocation.X += currentPic.Size.Width + 10; MainButton.Text = "Forfiet"; } }
private void RemovePaintEvent(PictureBox b) { FieldInfo f1 = typeof(Control).GetField("EventPaint", BindingFlags.Static | BindingFlags.NonPublic); object obj = f1.GetValue(b); PropertyInfo pi = b.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance); EventHandlerList list = (EventHandlerList)pi.GetValue(b, null); list.RemoveHandler(obj, list[obj]); }
/// <summary> /// 转换图像原始坐标在控件zoom情况下的位置 /// </summary> /// <param name="point"></param> Rectangle ConvertRect(PictureBox pictureBox, Rectangle originalRect) { if (pictureBox.Image == null) { return(new Rectangle(-1, -1, 0, 0)); } int originalWidth = pictureBox.Image.Width; int originalHeight = pictureBox.Image.Height; PropertyInfo rectangleProperty = pictureBox.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic); Rectangle rectangle = (Rectangle)rectangleProperty.GetValue(pictureBox, null); int currentWidth = rectangle.Width; int currentHeight = rectangle.Height; double rate = (double)currentHeight / (double)originalHeight; int black_left_width = (currentWidth == pictureBox.Width) ? 0 : (pictureBox.Width - currentWidth) / 2; int black_top_height = (currentHeight == pictureBox.Height) ? 0 : (pictureBox.Height - currentHeight) / 2; //int zoom_x = point.X - black_left_width; //int zoom_y = point.Y - black_top_height; //double original_x = (double)zoom_x / rate; //double original_y = (double)zoom_y / rate; StringBuilder sb = new StringBuilder(); //sb.AppendFormat("原始尺寸{0}/{1}(宽/高)\r\n", originalWidth, originalHeight); //sb.AppendFormat("缩放状态图片尺寸{0}/{1}(宽/高)\r\n", currentWidth, currentHeight); //sb.AppendFormat("缩放比率{0}\r\n", rate); //sb.AppendFormat("左留白宽度{0}\r\n", black_left_width); //sb.AppendFormat("上留白高度{0}\r\n", black_top_height); //sb.AppendFormat("当前鼠标坐标{0}/{1}(X/Y)\r\n", point.X, point.Y); //sb.AppendFormat("缩放图中鼠标坐标{0}/{1}(X/Y)\r\n", zoom_x, zoom_y); //sb.AppendFormat("原始图中鼠标坐标{0}/{1}(X/Y)\r\n", original_x, original_y); int x = Convert.ToInt32(originalRect.X * rate) + black_left_width; int y = Convert.ToInt32(originalRect.Y * rate) + black_top_height; int w = Convert.ToInt32(originalRect.Width * rate); int h = Convert.ToInt32(originalRect.Height * rate); Rectangle retRect = new Rectangle(x, y, w, h); return(retRect); //this.label1.Text = sb.ToString(); }
void picBox_MouseMove(object sender, MouseEventArgs e) { if ((DateTime.Now - dt).TotalMilliseconds < 5 || picBox.Image == null) { return; } dt = DateTime.Now; Point p = e.Location; Point screenPoint = picBox.PointToScreen(p); Point loc = new Point(screenPoint.X - formMagnifier.Width / 2, screenPoint.Y - formMagnifier.Height / 2); formMagnifier.Location = loc; PropertyInfo _ImageRectanglePropert = picBox.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic); Rectangle _Rectangle = (Rectangle)_ImageRectanglePropert.GetValue(picBox, null); float wR = (float)picBox.Image.Width / (float)_Rectangle.Width; bitmap = new Bitmap((int)(100 * wR), (int)(100 * wR)); float l = 0, t = 0; if (_Rectangle.Left > 0) { l = (p.X - _Rectangle.Left - 50) * wR; t = (p.Y - 50) * wR; } if (_Rectangle.Top > 0) { l = (p.X - 50) * wR; t = (p.Y - _Rectangle.Top - 50) * wR; } using (Graphics g = Graphics.FromImage(bitmap)) { g.DrawImage(picBox.Image, new RectangleF(0, 0, 100 * wR, 100 * wR), new RectangleF(l, t, 100 * wR, 100 * wR), GraphicsUnit.Pixel); g.DrawImage(mImageMagnifier, 0, 0, bitmap.Width, bitmap.Height); } picShow.Image = bitmap; }
protected virtual Control CreateImage(PropertyDescriptor property) { Control control; if (this.DataEntryControl.Site == null) { PictureBox pictureBox = new PictureBox(); EditorInitializingEventArgs e = new EditorInitializingEventArgs(property, (Control)pictureBox, pictureBox.GetType()); this.OnEditorInitializing((object)this, e); if (e.Cancel) { return((Control)null); } control = e.Editor; this.OnEditorInitialized((object)this, new EditorInitializedEventArgs(property, (Control)pictureBox, pictureBox.GetType())); } else { Control component = (Control)(this.designerHost.CreateComponent(typeof(PictureBox)) as PictureBox); EditorInitializingEventArgs e = new EditorInitializingEventArgs(property, component, component.GetType()); this.OnEditorInitializing((object)this, e); if (e.Cancel) { return((Control)null); } control = !object.ReferenceEquals((object)e.Editor, (object)component) ? this.designerHost.CreateComponent(e.EditorType) as Control : e.Editor; this.OnEditorInitialized((object)this, new EditorInitializedEventArgs(property, control, control.GetType())); } Binding binding = this.CreateBinding(control, "Image", property.Name); if (binding != null) { control.DataBindings.Add(binding); } return(control); }
public static void SetDoubleBuffered(this PictureBox listView, bool value) { listView.GetType() .GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic) .SetValue(listView, value); }