当前位置: 首页>>代码示例>>C#>>正文


C# PictureBox.GetType方法代码示例

本文整理汇总了C#中System.Windows.Forms.PictureBox.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# PictureBox.GetType方法的具体用法?C# PictureBox.GetType怎么用?C# PictureBox.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.PictureBox的用法示例。


在下文中一共展示了PictureBox.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoveClickEvent

 private static void RemoveClickEvent(PictureBox b)
 {
     var f1 = typeof(Control).GetField("EventDoubleClick", BindingFlags.Static | BindingFlags.NonPublic);
     var obj = f1?.GetValue(b);
     var pi = b.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance);
     var list = (EventHandlerList)pi.GetValue(b, null);
     list.RemoveHandler(obj, list[obj]);
 }
开发者ID:vlad324,项目名称:TransportSimulator,代码行数:8,代码来源:CreateVehicleForm.cs

示例2: picCutFunction

        /// <summary>
        /// 根据给定的图像及起点坐标和终点坐标截取图像,并储存,返回截取后的图像路径
        /// </summary>
        /// <param name="picBox">存放被截图像的PictureBox</param>
        /// <param name="picName">图像路径</param>
        /// <param name="start">起点</param>
        /// <param name="end">终点,起点必须在终点上方</param>
        /// <returns>返回截取后的图像路径</retu
        public static string picCutFunction(PictureBox picBox, Bitmap pic, Point start, Point end)
        {
            //-------debug-----
            //            MessageBox.Show(start.ToString() + "  end:"  + end.ToString());
            string picName = "original";
            try
            {

                //原图高
                int originalPicHeight = picBox.Image.Height;
                //获取图片缩放后的大小
                PropertyInfo rectangleProperty = picBox.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
                Rectangle rectangle = (Rectangle)rectangleProperty.GetValue(picBox, null);
                //图片显示的宽度
                int picShowWidth = rectangle.Width;
                int picShowHeight = rectangle.Height;
                //图片左边或者上边空白的宽度
                int picLeftWidth = (picShowWidth == picBox.Width) ? 0 : (picBox.Width - picShowWidth) / 2;
                int picTopHeight = (picShowHeight == picBox.Height) ? 0 : (picBox.Height - picShowHeight) / 2;

                //图片的缩放比例
                double rate = (double)picShowHeight / (double)originalPicHeight;

                //将显示坐标转换为原图坐标
                start.X = Convert.ToInt32((double)(start.X - picLeftWidth) / rate);
                start.Y = Convert.ToInt32((double)(start.Y - picTopHeight) / rate);
                end.X = Convert.ToInt32((double)(end.X - picLeftWidth) / rate);
                end.Y = Convert.ToInt32((double)(end.Y - picTopHeight) / rate);

                if (start.X < end.X && start.Y < end.Y)
                {
                    int xa = start.X;
                    int xb = end.X;
                    int ya = start.Y;
                    int yb = end.Y;

                    Rectangle rec = new Rectangle(0, 0, pic.Width, pic.Height);
                    BitmapData bd = pic.LockBits(rec, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                    IntPtr ptr = bd.Scan0;
                    int bytes = bd.Stride * bd.Height;
                    byte[] rgbvalues = new byte[bytes];
                    System.Runtime.InteropServices.Marshal.Copy(ptr, rgbvalues, 0, bytes);
                    int w;
                    int h;
                    w = xb - xa;
                    h = yb - ya;
                    Bitmap pic1 = new Bitmap(w, h);// (Application.StartupPath + @"\11.jpg");
                    Rectangle rec6 = new Rectangle(0, 0, w, h);
                    BitmapData bd6 = pic1.LockBits(rec6, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                    IntPtr ptr6 = bd6.Scan0;
                    int bytes6 = bd6.Stride * bd6.Height;
                    byte[] rgbvalues6 = new byte[bytes6];
                    System.Runtime.InteropServices.Marshal.Copy(ptr6, rgbvalues6, 0, bytes6);

                    for (int i = xa; i < xb; i++)
                    {
                        for (int j = ya; j < yb; j++)
                        {
                            rgbvalues6[(j - ya) * bd6.Stride + (i - xa) * 3] = rgbvalues[j * bd.Stride + i * 3];
                            rgbvalues6[(j - ya) * bd6.Stride + (i - xa) * 3 + 1] = rgbvalues[j * bd.Stride + i * 3 + 1];
                            rgbvalues6[(j - ya) * bd6.Stride + (i - xa) * 3 + 2] = rgbvalues[j * bd.Stride + i * 3 + 2];
                        }
                    }

                    System.Runtime.InteropServices.Marshal.Copy(rgbvalues6, 0, ptr6, bytes6);
                    pic1.UnlockBits(bd6);
                    pic1.Save(Application.StartupPath + @"\Temp\" + Path.GetFileNameWithoutExtension(picName) + "_cuted.jpg");  //存储剪切后的图片
                    pic1.Dispose();

                    return Application.StartupPath + @"\Temp\" + Path.GetFileNameWithoutExtension(picName) + "_cuted.jpg";
                }
                else
                {
                    //                    MessageBox.Show("划线未完成,请重新划线!");
                    return "";
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("系统出错,请重试!---1 " + err.Message + "\n当前处理图片: " + picName);
                return "";
            }
        }
开发者ID:blueyi,项目名称:density_figure,代码行数:91,代码来源:PicFunction.cs

示例3: getPictureBoxOffset

        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);
            //return new Point(rectangle.X, rectangle.Y);
        }
开发者ID:bsimser,项目名称:goldbox,代码行数:12,代码来源:GeoDaxFileViewer.cs


注:本文中的System.Windows.Forms.PictureBox.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。