private void InvertRegion() { // Graphics g = this.CreateGraphics(); // bool result = InvertRect( g.GetHdc(), ref this.rect); ControlPaint.FillReversibleRectangle(this.rect, Color.Black); ControlPaint.DrawReversibleFrame(this.rect, Color.Black, FrameStyle.Dashed); }
private void Horizontal_MouseMove(object sender, MouseEventArgs e) { if (Action == SizeAction.SizeH && e.Button == MouseButtons.Left) { Point start; int x = e.X; int y = e.Y; if (y + Horizontal.Top > Height - 4) { y = Height - 4 - Horizontal.Top; } if (y + Horizontal.Top < 0) { y = 0 - Horizontal.Top; } if (!FirstTime) { start = PointToScreen(Location); start.Y += PrevPos.Y + Horizontal.Location.Y; ControlPaint.FillReversibleRectangle(new Rectangle(start.X, start.Y, Width, 3), Color.Black); } else { FirstTime = false; } start = PointToScreen(Location); start.Y += y + Horizontal.Location.Y; ControlPaint.FillReversibleRectangle(new Rectangle(start.X, start.Y, Width, 3), Color.Black); PrevPos = new Point(x, y); } }
/// <summary> /// ドラッグ先を表す縦のラインを描画 /// </summary> /// <param name="index">描画するボタンのインデックス (-1なら線を消す)</param> protected void DrawHorzLine(int index) { if (tempDropLine != Rectangle.Empty) { ControlPaint.FillReversibleRectangle(tempDropLine, Color.Black); } if (index >= 0) { CSharpToolBarButton button = (index < Buttons.Count) ? Buttons[index] : Buttons[Buttons.Count - 1]; Rectangle rc = button.Bounds; rc.Width = 2; if (index >= Buttons.Count) { rc.X = button.Bounds.Right - 2; } tempDropLine = RectangleToScreen(rc); using (Graphics g = CreateGraphics()) ControlPaint.FillReversibleRectangle(tempDropLine, Color.Black); } else { tempDropLine = Rectangle.Empty; } }
private void Vertical_MouseMove(object sender, MouseEventArgs e) { if (Action == SizeAction.SizeV && e.Button == MouseButtons.Left) { Point start; int x = e.X; int y = e.Y; if (x + Vertical.Left > Width - 4) { x = Width - 4 - Vertical.Left; } if (x + Vertical.Left < 0) { x = 0 - Vertical.Left; } if (!FirstTime) { start = PointToScreen(Location); start.X += PrevPos.X + Vertical.Location.X; ControlPaint.FillReversibleRectangle(new Rectangle(start.X, start.Y, 3, Height), Color.Black); } else { FirstTime = false; } start = PointToScreen(Location); start.X += x + Vertical.Location.X; ControlPaint.FillReversibleRectangle(new Rectangle(start.X, start.Y, 3, Height), Color.Black); PrevPos = new Point(x, y); } }
private void invert() { if (m_InvertRect.X != 0 && m_InvertRect.Y != 0) { ControlPaint.FillReversibleRectangle(m_InvertRect, Color.Beige); } }
private void Center_MouseMove(object sender, MouseEventArgs e) { if (Action == SizeAction.SizeA && e.Button == MouseButtons.Left) { Point start; int x = e.X - Center.Width / 2; int y = e.Y - Center.Height / 2; if (!FirstTime) { start = this.PointToScreen(this.Location); start.X += PrevPos.X + Vertical.Location.X; ControlPaint.FillReversibleRectangle(new Rectangle(start.X, start.Y, 3, this.Height), Color.Black); start = this.PointToScreen(this.Location); start.Y += PrevPos.Y + Horizontal.Location.Y; ControlPaint.FillReversibleRectangle(new Rectangle(start.X, start.Y, this.Width, 3), SystemColors.ControlDark); } else { FirstTime = false; } start = this.PointToScreen(this.Location); start.X += x + Vertical.Location.X; ControlPaint.FillReversibleRectangle(new Rectangle(start.X, start.Y, 3, this.Height), Color.Black); start = this.PointToScreen(this.Location); start.Y += y + Horizontal.Location.Y; ControlPaint.FillReversibleRectangle(new Rectangle(start.X, start.Y, this.Width, 3), SystemColors.ControlDark); PrevPos = new Point(x, y); } }
public void DrawFilledRectangle(Point start, Size size, Color color) { ValidateCoordinates(ref start, ref size); start = SceneControl.PointToScreen(start); ControlPaint.FillReversibleRectangle(new Rectangle(start, size), color); }
// When the mouse leaves Button2, its ClientRectangle is cleared by // calling the FillReversibleRectangle method again. private void Button2_MouseLeave(object sender, System.EventArgs e) { Control senderControl = (Control)sender; Rectangle screenRectangle = senderControl.RectangleToScreen( senderControl.ClientRectangle); ControlPaint.FillReversibleRectangle(screenRectangle, senderControl.BackColor); }
public static void DrawInsertIndicatorH(int x, int y, int width, Graphics g, Color c) { y -= 3; x -= 2; ControlPaint.FillReversibleRectangle(new Rectangle(x, y, 2, 7), c); ControlPaint.FillReversibleRectangle(new Rectangle(x + 2, y + 1, width, 5), c); ControlPaint.FillReversibleRectangle(new Rectangle(width + 2 + x, y, 2, 7), c); }
public static void DrawInsertIndicatorV(int x, int y, int height, Graphics g, Color c) { x -= 3; y -= 2; ControlPaint.FillReversibleRectangle(new Rectangle(x, y, 7, 2), c); ControlPaint.FillReversibleRectangle(new Rectangle(x + 1, y + 2, 5, height), c); ControlPaint.FillReversibleRectangle(new Rectangle(x, height + 2 + y, 7, 2), c); }
private void Center_MouseMove(object sender, MouseEventArgs e) { if (Action == SizeAction.SizeA && e.Button == MouseButtons.Left) { Point start; int x = e.X - Center.Width / 2; int y = e.Y - Center.Height / 2; // ROB: Added fix for graphics splatter when sizing both splitters. if (y + Horizontal.Top > Height - 4) { y = Height - 4 - Horizontal.Top; } if (y + Horizontal.Top < 0) { y = 0 - Horizontal.Top; } if (x + Vertical.Left > Width - 4) { x = Width - 4 - Vertical.Left; } if (x + Vertical.Left < 0) { x = 0 - Vertical.Left; } // END-ROB if (!FirstTime) { start = PointToScreen(Location); start.X += PrevPos.X + Vertical.Location.X; ControlPaint.FillReversibleRectangle(new Rectangle(start.X, start.Y, 3, Height), Color.Black); start = PointToScreen(Location); start.Y += PrevPos.Y + Horizontal.Location.Y; ControlPaint.FillReversibleRectangle(new Rectangle(start.X, start.Y, Width, 3), SystemColors.ControlDark); } else { FirstTime = false; } start = PointToScreen(Location); start.X += x + Vertical.Location.X; ControlPaint.FillReversibleRectangle(new Rectangle(start.X, start.Y, 3, Height), Color.Black); start = PointToScreen(Location); start.Y += y + Horizontal.Location.Y; ControlPaint.FillReversibleRectangle(new Rectangle(start.X, start.Y, Width, 3), SystemColors.ControlDark); PrevPos = new Point(x, y); } }
private void InvertRegion() { if ((this.rect.Width + this.rect.Height) != 0) { ControlPaint.FillReversibleRectangle(this.rect, Color.White); ControlPaint.DrawReversibleFrame(this.rect, Color.Black, FrameStyle.Dashed); } return; }
void pbCanvas_MouseLeave(object sender, EventArgs e) { int h = pbCanvas.ClientSize.Height; if (lastX >= 0) { ControlPaint.FillReversibleRectangle(new Rectangle(pbCanvas.PointToScreen(new Point(lastX, lastY)), new Size(DX, DX)), Color.Gray); lastX = lastY = -1; } }
protected internal override void OnMouseDrag(MouseEventArgs e) { base.OnMouseDrag(e); if (m_Grid.m_ResizingColumn == null) { return; } var rect = DisplayRegion; rect.Offset(e.X - m_GrabX, 0); rect.Y = 1; rect.Height = m_Host.Height - 1; invert(); m_InvertRect = m_Host.RectangleToScreen(rect); ControlPaint.FillReversibleRectangle(m_InvertRect, Color.Beige); }
/// <summary> /// draw rectangle function /// </summary> /// <param name="backColor">back color</param> public void Draw(Color backColor) { //Initialize the 8 little rectangles SetLittleRectangle(); //draw the main rectangle and the 8 little rectangles ControlPaint.DrawReversibleFrame(rect, backColor, FrameStyle.Dashed); ControlPaint.FillReversibleRectangle(leftTopRectangle, Color.White); ControlPaint.FillReversibleRectangle(leftMiddleRectangle, Color.White); ControlPaint.FillReversibleRectangle(leftBottomRectangle, Color.White); ControlPaint.FillReversibleRectangle(rightTopRectangle, Color.White); ControlPaint.FillReversibleRectangle(rightMiddleRectangle, Color.White); ControlPaint.FillReversibleRectangle(rightBottomRectangle, Color.White); ControlPaint.FillReversibleRectangle(topMiddleRectangle, Color.White); ControlPaint.FillReversibleRectangle(bottomMiddleRectangle, Color.White); }
private void DrawHorizontalSelection(Point start, Point end, UserControl ctr) { // the clipping rectangle in screen coordinates Rectangle clip = ctr.RectangleToScreen( new Rectangle( (int)ps_.PlotAreaBoundingBoxCache.X, (int)ps_.PlotAreaBoundingBoxCache.Y, (int)ps_.PlotAreaBoundingBoxCache.Width, (int)ps_.PlotAreaBoundingBoxCache.Height)); start = ctr.PointToScreen(start); end = ctr.PointToScreen(end); ControlPaint.FillReversibleRectangle( new Rectangle((int)Math.Min(start.X, end.X), (int)clip.Y, (int)Math.Abs(end.X - start.X), (int)clip.Height), Color.White); }
protected void DrawReversibleRectangle(Point p1, Point p2) { if (p1 == p2) { return; } p1 = this.PointToScreen(p1); p2 = this.PointToScreen(p2); int left = Math.Min(p1.X, p2.X); int right = Math.Max(p1.X, p2.X); int top = Math.Min(p1.Y, p2.Y); int bottom = Math.Max(p1.Y, p2.Y); Rectangle rect = new Rectangle(left, top, right - left, bottom - top); Color color = Color.LightGray; //color.A = 0.5; //ControlPaint.DrawReversibleFrame(rect, color, FrameStyle.Dashed); ControlPaint.FillReversibleRectangle(rect, Color.Transparent); }
protected internal override void OnMouseDrag(MouseEventArgs e) { base.OnMouseDrag(e); if (m_Grid.m_RepositioningColumn == null) { return; } var rect = DisplayRegion; rect.Offset(e.X - m_GrabX, 0); rect.X = Math.Max(0, rect.X); rect.X = Math.Min(m_Grid.CellView.Right - (int)(m_Grid.m_RepositioningColumn.Width * m_Host.Zoom), rect.X); rect.Y = 1; rect.Height = m_Host.Height - 1; invert(); m_InvertRect = m_Host.RectangleToScreen(rect); ControlPaint.FillReversibleRectangle(m_InvertRect, Color.Beige); }
void pbCanvas_MouseMove(object sender, MouseEventArgs e) { int w = pbCanvas.ClientSize.Width, h = pbCanvas.ClientSize.Height; int d = h / 20; using (Graphics g = pbCanvas.CreateGraphics()) { int X = e.X - e.X % DX, Y = e.Y - e.Y % d; if ((X != lastX || Y != lastY) && Y / d < 20) { if (lastX >= 0) { ControlPaint.FillReversibleRectangle(new Rectangle(pbCanvas.PointToScreen(new Point(lastX, lastY)), new Size(DX, DX)), Color.Gray); } ControlPaint.FillReversibleRectangle(new Rectangle(pbCanvas.PointToScreen(new Point(X, Y)), new Size(DX, DX)), Color.Gray); lastX = X; lastY = Y; } } }
protected override void OnPaint(PaintEventArgs e) { g = e.Graphics; // Create a red brush Brush redBrush = new SolidBrush(Color.Red); // Fill rectangle g.FillRectangle(redBrush, aRect); // Create a green brush Brush greenBrush = new SolidBrush(Color.Green); // Fill ellipse g.FillEllipse(greenBrush, anEllipse); while (x < 500) { moving.Location = this.PointToScreen(new Point(x, y)); ControlPaint.FillReversibleRectangle(moving, Color.Red); Thread.Sleep(10); ControlPaint.FillReversibleRectangle(moving, Color.Red); x++; y++; } }
private static void DrawSplitIndicator(Rectangle drawRect) { // We just perform a simple reversible rectangle draw ControlPaint.FillReversibleRectangle(drawRect, Color.Black); }
private void button1_Click(object sender, EventArgs e) { int x = Convert.ToInt32(textBox1.Text); int y = Convert.ToInt32(textBox2.Text); Color color = GetPixelColor(x, y); listBox1.Items.Add(color.ToString()); //var g = this.CreateGraphics(); #region main pointLeftUp = new Point(Convert.ToInt32(textBox3.Text), Convert.ToInt32(textBox5.Text)); pointRightDown = new Point(Convert.ToInt32(textBox4.Text), Convert.ToInt32(textBox6.Text)); int width = pointRightDown.X - pointLeftUp.X; int height = pointRightDown.Y - pointLeftUp.Y; Bitmap bitmap = new Bitmap(width, height); //下面这句话把graphics和bitmap联系在一起!! Graphics gSave = Graphics.FromImage(bitmap); gSave.CopyFromScreen(pointLeftUp, new Point(0, 0), new Size(width, height)); bitmap.Save(Application.StartupPath + DateTime.Now.Year + ".png"); BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb); IntPtr bmpPtr = bmpData.Scan0; int bytesCount = bmpData.Stride * bmpData.Height; if (rgbValues == null) { rgbValues = new byte[bytesCount]; } //byte[] rgbValues = new byte[bytesCount];//1410000=4*750*470 //from bmpPtr to rgbValues Marshal.Copy(bmpPtr, rgbValues, 0, bytesCount); //height=行数 //width =列数 byte originalByte = (byte)((rgbValues[0] + rgbValues[1] + rgbValues[2]) / 3); byte newByte = 0; for (int i = 0; i < height; i += 2) //rows 每次隔5pixel { for (int j = 0; j < width; j += 2) // { //下面这行i*4 太bug了。一定要注意索引啊!! newByte = (byte)((rgbValues[i * width * 4 + j * 4] + rgbValues[i * width * 4 + j * 4 + 1] + rgbValues[i * width * 4 + j * 4 + 2]) / 3); if (originalByte != newByte) { int tempx = j; //列 int tempy = i; //行 Point result = new Point(pointLeftUp.X + tempx, pointLeftUp.Y + tempy); Rectangle rect = new Rectangle(result, new Size(5, 5)); //ControlPaint.DrawReversibleFrame(rect, Color.Red, FrameStyle.Dashed); ControlPaint.FillReversibleRectangle(rect, Color.Black); Point buttonPoint; NativeMethods.GetCursorPos(out buttonPoint); NativeMethods.SetCursorPos(result.X, result.Y); NativeMethods.mouse_event((int)(NativeMethods.MouseEventFlags.LEFTDOWN), 0, 0, 0, 0); NativeMethods.mouse_event((int)NativeMethods.MouseEventFlags.LEFTUP, 0, 0, 0, 0); NativeMethods.SetCursorPos(buttonPoint.X, buttonPoint.Y); return; } } } #endregion //Graphics g = Graphics.FromHdc(this.Handle); ////g.ClipBounds.Width ////Image image = new Bitmap(Application.StartupPath+"BadPoint.png"); //Image image=new Bitmap((int)g.ClipBounds.Width,(int)g.ClipBounds.Height); //g.CopyFromScreen(100, 517, 0, 0, new Size(762, 474)); //g.DrawImage(image, 0, 0); //image.Save(Application.StartupPath+"BadPoint.png"); }