
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
m_MouseIsDown = true;
DrawStart(new Point(e.X, e.Y));
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (m_MouseIsDown) ResizeToRectangle(new Point(e.X, e.Y));
}
float w = 0;//宽度比例
float h = 0;//高度比例
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
w = (float)intwidth / (float)pictureBox1.Width;
h = (float)intheigh / (float)pictureBox1.Height;
Cursor.Clip = Rectangle.Empty;
m_MouseIsDown = false;
DrawRectangle();
if (m_MouseRect.X == 0 || m_MouseRect.Y == 0 || m_MouseRect.Width == 0 || m_MouseRect.Height == 0)
{
//如果区域没0 就不执行委托
}
else
{
if (SetRectangel != null) SetRectangel(pictureBox1, m_MouseRect);
}
ControlPaint.DrawReversibleFrame(pictureBox1.RectangleToScreen(m_MouseRect), Color.Red, FrameStyle.Thick);
System.Drawing.Bitmap bmp = new Bitmap(pictureBox1.Image);
Graphics m_mouse = Graphics.FromImage(bmp);
Brush brush = new SolidBrush(Color.Red);
Pen pen = new Pen(brush, 3);
int wd = (int)(w * m_MouseRect.Width);
int hd = (int)(h * m_MouseRect.Height);
m_mouse.DrawEllipse(pen, new Rectangle((int)(m_MouseRect.X * w), (int)(h * m_MouseRect.Y), wd, hd));
m_mouse.DrawRectangle(pen, new Rectangle((int)(m_MouseRect.X * w), (int)(h * m_MouseRect.Y), wd, hd));
//MemoryStream ms = new MemoryStream();
// bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
bmp.Save("D://1.bmp");
pictureBox3.Image = bmp;
//截屏可以实现效果
Bitmap myImage = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics g = Graphics.FromImage(myImage);
g.CopyFromScreen(pictureBox1.PointToScreen(pictureBox1.Location), new Point(0, 0), pictureBox1.PreferredSize);
IntPtr dc1 = g.GetHdc();
g.ReleaseHdc(dc1);
pictureBox2.Image = (Image)myImage;
}
/// <summary>
/// 刷新绘制
/// </summary>
/// <param name="p"></param>
private void ResizeToRectangle(Point p_Point)
{
DrawRectangle();
m_MouseRect.Width = p_Point.X - m_MouseRect.Left;
m_MouseRect.Height = p_Point.Y - m_MouseRect.Top;
DrawRectangle();
}
/// <summary>
/// 绘制区域
/// </summary>
private void DrawRectangle()
{
Rectangle _Rect = pictureBox1.RectangleToScreen(m_MouseRect);
ControlPaint.DrawReversibleFrame(_Rect, Color.White, FrameStyle.Dashed);
}
/// <summary>
/// 开始绘制 并且设置鼠标区域
/// </summary>
/// <param name="StartPoint">开始位置</param>
private void DrawStart(Point p_Point)
{
Cursor.Clip = pictureBox1.RectangleToScreen(new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
m_MouseRect = new Rectangle(p_Point.X, p_Point.Y, 0, 0);
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
pictureBox1.MouseDown+=new MouseEventHandler(pictureBox1_MouseDown);
pictureBox1.MouseMove+=new MouseEventHandler(pictureBox1_MouseMove);
pictureBox1.MouseUp += new MouseEventHandler(pictureBox1_MouseUp);
}
private Rectangle m_MouseRect = Rectangle.Empty;
public delegate void SelectRectangel(object sneder, Rectangle e);
public event SelectRectangel SetRectangel;
private bool m_MouseIsDown = false;
int intwidth = 0;
int intheigh = 0;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
m_MouseIsDown = true;
DrawStart(new Point(e.X, e.Y));
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (m_MouseIsDown) ResizeToRectangle(new Point(e.X, e.Y));
}
float w = 0;//宽度比例
float h = 0;//高度比例
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
w = (float)intwidth / (float)pictureBox1.Width;
h = (float)intheigh / (float)pictureBox1.Height;
Cursor.Clip = Rectangle.Empty;
m_MouseIsDown = false;
DrawRectangle();
if (m_MouseRect.X == 0 || m_MouseRect.Y == 0 || m_MouseRect.Width == 0 || m_MouseRect.Height == 0)
{
//如果区域没0 就不执行委托
}
else
{
if (SetRectangel != null) SetRectangel(pictureBox1, m_MouseRect);
}
DrawRectangle();
//ControlPaint.DrawReversibleFrame(pictureBox1.RectangleToScreen(m_MouseRect), Color.Red, FrameStyle.Thick);
}
/// <summary>
/// 刷新绘制
/// </summary>
/// <param name="p"></param>
private void ResizeToRectangle(Point p_Point)
{
DrawRectangle();
m_MouseRect.Width = p_Point.X - m_MouseRect.Left;
m_MouseRect.Height = p_Point.Y - m_MouseRect.Top;
DrawRectangle();
}
/// <summary>
/// 绘制区域
/// </summary>
private void DrawRectangle()
{
Rectangle _Rect = pictureBox1.RectangleToScreen(m_MouseRect);
ControlPaint.DrawReversibleFrame(_Rect, Color.White, FrameStyle.Dashed);
}
/// <summary>
/// 开始绘制 并且设置鼠标区域
/// </summary>
/// <param name="StartPoint">开始位置</param>
private void DrawStart(Point p_Point)
{
Cursor.Clip = pictureBox1.RectangleToScreen(new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
m_MouseRect = new Rectangle(p_Point.X, p_Point.Y, 0, 0);
}
}
//保存127*229的图片_S //File.Copy(imagepath, temppath, true); //拷贝文件 bmp = new Bitmap(imagepath); bmp_S = new Bitmap(bmp, 127, 229); //bmp_S.Save(imagepath_S, ImageFormat.Jpeg);...
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading....using System.W...
转自:... c#PictureBox的基本使用(画直线,矩形) 下面的四个事件一定要绑定,不绑定任何效果都没有的 private Point m_ptStart = new Point(0, 0); private Point m_ptEnd = new Point(0, 0);
要求:设计一个根据鼠标来绘制矩形框的程序,即当按下鼠标左键并拖动至某个位置后释放鼠标使,可根据按下鼠标时的第一个点和释放鼠标时的第二个点来确定并绘制该矩形。设计思路:1.首先得到首次鼠标点击的位置 ,...
下面我们以多屏画视频播放的边框为例。 错误效果: 期望效果: /// <summary> /// 绘制播放视频控件边框(0:黑色,1:绿色) /// </summary> /// <param name="...
最近在用C#进行编程,重写CheckBox,需要绘画圆角矩形,在网上查找了许多资料,用C#FillPath的方式绘画总感觉太麻烦,需要算坐标,不如直接调用C++的方法绘画圆角矩形。 声明:本代码借鉴网上代码,在此仅做整理出来...
private void label1_Paint(object sender, PaintEventArgs e) { Draw(e.ClipRectangle, e.Graphics, 16); base.OnPaint(e); } private void Draw(Rectangle rectangle, Gr
当拖动窗体是,窗体发生移动,window默认为从窗体移动到另一个地方,先发生擦除后再重新画一个窗体; 而我们自己动手画的图(如下面的线),不会重新画;在属性中,Paint,中,将画图的程序重新写一遍就可实现重画。 ...
C# 中在图像上画框,通过鼠标来实现主要有四个消息响应函数MouseDown, MouseMove, MouseUp, Paint重绘函数实现。当鼠标键按下时开始画框,鼠标键抬起时画框结束。 1 2 Point start; //画框的...
C# 画圆角矩形
先大概介绍一下原因,GDI画矩形框就不说了,很简单的。这里面最主要的就是滚轮放大和左键移动两个事件,要计算矩形框的坐标位置。下面将代码贴出如下: 先是定义需要的变量,就四个变量。 //矩形框坐标 private ...
1.旋转矩形 说明: 一个矩形绕着中心点旋转任意角度后得到一个旋转的矩形。 我参考了这篇文章里xuzuning的方法,写一个旋转矩形的方法。 旋转矩形代码: private void Rect2Pointfs(Rectangle rect, float ...
我利用opencv在一张图片上画了若干个矩形,想给每一个矩形添加鼠标监听事件来操作它们,不知道如何完成,或者有其他方法完成这种功能? { var pa = point - rect[0]; var pb = point - rect[1]; var pc = point - rect[2]; var pd = point - rect[3];...
1.矩形框的绘制 绘制矩形框是用GDI+技术的DrawRectangle方法来实现的,它有3种语法,其语法格式如下: public void DrawRectangle (Pen pen, int x, int y, int width, int height) public void ...
为什么要学习C#?C#是微软的王牌语言,拥有接近20年的历史和广泛的应用。目前国内对C#的书籍和视频相对较少,但C#和.NET的发展前程是十分光明的,这体现在微软公司本身强劲的实力,C#的开源,.NET Core社区的蓬勃...
在桌面上画矩形 void showRectInDesktop(RECT & rect) { // 获得DC HDC hDC = ::GetDC(0); // 创建实线,宽度为1,红色的笔 HPEN hPen = ::CreatePen(PS_SOLID, 4, RGB(255,0,0)); // 将笔选入DC HPEN hOldPen...
创建画布的3种方法: 1.最常用的就是Button按钮,方便刷新时间 Private void button1_Click (object Sender, EventArgs e) { Graphics g=this.CreateGraphics(); ... protected override void OnPaint...
Bitmap b = new Bitmap(panel1.Width, panel1.Height); Graphics g = Graphics.FromImage(b); Rectangle rect = new Rectangle((panel1.Width / 2) - 128, (panel1.Height / 2) - 152, 256,
Form1.cs 代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms...namespa...
开发工具与技术:工具:Visual Studio/c#,技术:C# 作者:刘胜 撰写时间:2019-02-16 1.创建简单的多维数组 在开发游戏中要运用多维数组,方便利用和储存更多的数据,多维数组的维数跟嵌套多少个for循环有关, ...
如何获取两个矩形不重叠区域的GraphicsPath
利用C#的窗口程序开发一个简易画板 父窗体 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; ...
本次课程是初级课程,只要熟悉计算机的基本...本课程深入浅出的介绍了C#语言的基本语法结构、条件选择、循环、异常处理、数组、集合、值类型和应用类型、字符串的常用方法、日期类型的案例应用、各种方法的灵活等等。
C#获取服务 C#获取服务状态 C#判断服务状态 C#监听服务状态 C#启动服务
文章目录一、VS的开发环境二、创建C#窗体应用程序三、创建控制台应用程序四、创建Web 一、VS的开发环境 首先你得安装了vs2019,然后确认下下面三个组件是否存在,如果没有要下载一下。vs2019的安装可参考visual ...
质数:是只有1和它本身两个约数的...下面是C#判断是否为质数的方法。 /// <summary> /// 高效判断是否为质数 /// </summary> public static bool isPrime(long num) { if (n...
问题描述:设计一个根据鼠标来绘制矩形框的程序,即当按下鼠标左键并拖动至某个位置后释放鼠标使,可根据按下鼠标时的第...3.调用DrawRectangle画出矩形。具体实现:using System; using System.Collections.Gen...