Timer 和 画布Graphics
几个重点:
Timer控件的使用
Graphics 的各种Draw方法
Brush,Pen
Paint事件
双缓冲
控件timer:计时器
属性:enabled true/false 是否可用,即在加载的时候是否启用事件
interval 1000 1000毫秒就是1秒
timer控件有一个事件:Tick 表示的是当一个时间到来的时候做的事
窗体加载时鼠标的三个事件:
mousedown 鼠标点击时事件
mousemove 鼠标移动时事件
mouseup 鼠标弹起事件
string url=@ "图片路径"; 有两种方法解决转义符的问题,在路径用\\或者在最前面加@
1、比如双\\ "C:\\Users\\越\\Desktop\\2"
2、在前面加string url=@“C:\Users\越\Desktop\2”;
图片的路径可以用string 类型的变量来赋值;
在窗体里面插入一张图片:
this.backgroundImage=image.fromfire(url);
paint 窗体的事件,加载时画窗体
refresh();强制整个窗体重绘,这是一个方法,直接调用就好了
graphics g=this.creatgraphics();// 这步是在得到基于该窗体的图形(画布)对象
pen p=new penpal(color.Red); //得到一支红色的画笔,颜色可以自定义也就是Red可以是Black等等
g.Drawling(p,x,y,e.x,e.y); //这是在画一个矩形
g.DrawEllipse(p, x, y, width, height); //这是在画一个椭圆
g.DrawRectangle(p,x,y,width,height); //这是在画一个矩形
g.DrawLine(p,x,y,e.X,e.Y); //这是在画一条直线双缓冲:this.Doublebuffered=true;
1、在应用程序中使用双缓冲的最简便的方法是使用 .NET Framework 为窗体和控件提供的默认双缓冲。通过将 DoubleBuffered 属性设置为 true。 //还不能完全理解是什么意思,只知道他能让几张图片交互时更流畅 ,比如即将做的项目 "Flappy bird"小鸟要飞;
在窗体上 -- 画圆、直线、椭圆、随意涂鸦
1、画圆、椭圆
int x, y;
bool IsDownMouse = false;
private void Form6_MouseDown(object sender, MouseEventArgs e) //鼠标点击时
{
x = e.X;
y = e.Y;
IsDownMouse = true;
}
private void Form6_MouseMove(object sender, MouseEventArgs e) //鼠标移动时
{
//清空
if (IsDownMouse==true)
{
Refresh();
int width = e.X - x; //记录当前位置
int height = e.Y - y;
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Black);
g.DrawEllipse(p, x, y, width, height);
}
}
private void Form6_MouseUp(object sender, MouseEventArgs e) //鼠标按键弹起时
{
IsDownMouse = false;
}
2、画矩形
int x, y;
bool IsMouseDowns=false;
private void Form7_MouseDown(object sender, MouseEventArgs e) //鼠标点击时
{
x = e.X;
y = e.Y;
IsMouseDowns = true;
}
private void Form7_MouseMove(object sender, MouseEventArgs e) //鼠标移动时
{
if (IsMouseDowns==true)
{
Refresh();
int width = e.X - x; //记录当前位置
int height = e.Y - y;
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Black);
g.DrawRectangle(p,x,y,width,height);
}
}
private void Form7_MouseUp(object sender, MouseEventArgs e) //鼠标按键弹起时
{
IsMouseDowns = false;
}
3、直线
int x, y;
bool IsMouseDown = false;
private void Form8_MouseDown(object sender, MouseEventArgs e) //鼠标点击时
{
x = e.X;
y = e.Y;
IsMouseDown = true;
}
private void Form8_MouseMove(object sender, MouseEventArgs e) //鼠标移动时
{
if (IsMouseDown==true)
{
Refresh();
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Black);
g.DrawLine(p,x,y,e.X,e.Y);
}
}
private void Form8_MouseUp(object sender, MouseEventArgs e) //鼠标按键弹起时
{
IsMouseDown = false;
}
4、随意涂鸦
int x, y;
bool isMouseDown=false;
//鼠标点击时
private void Form5_MouseDown(object sender, MouseEventArgs e)
{
x = e.X;
y = e.Y;
isMouseDown = true;
}
//鼠标移动时
private void Form5_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown==true)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Black);
g.DrawLine(p, x, y, e.X, e.Y);
x = e.X;
y = e.Y;
}
}
//鼠标按键弹起时
private void Form5_MouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;
}
相关推荐
C语言02-Timer0-Timer1-Timer2-Timer3-Timer4测试程序(STC32G-DEMO-CODE-220311kw)C语言02-Timer0-Timer1-Timer2-Timer3-Timer4测试程序(STC32G-DEMO-CODE-220311kw)C语言02-Timer0-Timer1-Timer2-Timer3-Timer4...
Android---Service Timer之执行周期任务
Arduino-arduino-timer.zip,用于延迟函数调用的非阻塞库arduino timer-用于延迟函数调用的库,Arduino是一家开源软硬件公司和制造商社区。Arduino始于21世纪初,深受电子制造商的欢迎,Arduino通过开源系统提供了很多...
精彩编程与编程技巧-让Timer控件每5分钟触发一次事件 ...
圆形/带颜色和进度动画的React / React Native倒数计时器组件。 倒计时动画针对Web和移动进行了独立优化 倒计时期间颜色之间的过渡 圆心完全可自定义的内容 a11y支持 内置的即用型TypeScript类型定义。 React yarn...
STC8a8k所有定时器测试程序
hal-adc-dma-timer.rar
前端项目-d3-timer,一个高效的队列,能够管理数千个并发动画。
yarn add react-native-background-timer # or using npm npm install react-native-background-timer --save 链接 React Native 后台计时器库。 当您使用 React Native >= 0.60(并且您的应用程序未从 Expo 中弹出...
dw-apb-timer手册中文版
an4776-generalpurpose-timer-cookbook-for-stm32-microcontrollers-stmicroelectro
名称:1-click-timer -------------------- 版本:8.3.1 作者:Made in Sweden 分类:学习办公 -------------------- 概述:一键设置计时器! 描述: 一键设置计时器! *快捷方便 *时尚的设计 *离线工作 *安全:不...
资源分类:Python库 所属语言:Python 资源全名:nose2-test-timer-0.0.3.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Swift-定时器scheduledTimer
12-2-1-定时器 Timer-相关例程演示 12-2-2-定时器 Timer-特性及时钟 12-2-3-定时器 Timer-模式
电子-STM32Timer4X4KEY.zip,单片机/嵌入式STM32-F0/F1/F2
前端开源库-metrics-timer度量计时器,用于应用程序度量的简单计时器
STM32CubeMX实现STM32 USBHID双向64字节通信(Qt上位机部分),使用Qt完成与STM32的usbhid通信,实现主动发送和定时器定时接收功能。
Zynq-Linux中timer中断的设计源码加axi-timer的参考文档
http-timer:对HTTP请求进行计时