为了账号安全,请及时绑定邮箱和手机立即绑定

pictureBox如何改变控件位置

pictureBox如何改变控件位置

幕布斯7119047 2018-12-06 19:08:10
界面:button,timer,picturebox 代码: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Drawing.Drawing2D;namespace PictureSport; { public partial class Test_Picture_Yuan : Form { public Test_Picture_Yuan() { InitializeComponent(); } private Graphics g; private Bitmap bmp; private Pen pen; private Point start; private Point stop; Bitmap image1; public Point P_lo; private void Test_Picture_Yuan_Load(object sender, EventArgs e) { timer1.Enabled = false; bmp = new Bitmap(this.Width, this.Height); g = Graphics.FromImage(bmp); //g = this.CreateGraphics(); pen = new Pen(Color.Red); } int i = 1; private void Test_Picture_Yuan_MouseClick(object sender, MouseEventArgs e) { if (i == 1) { start = e.Location; i++; } else { if (i == 2) { stop = e.Location; g.DrawLine(pen, start, stop); i++; this.BackgroundImage = bmp; } } } private void button1_Click(object sender, EventArgs e) { // g.DrawLine(pen, start, stop); //直线的坐标 横轴坐标不变, 纵轴坐标+ - 50 //(pen,start,stop) (pen,new Point (start.X,start.Y-50),new Point (stop.X,stop.Y-50)) (pen, new Point(start.X, start.Y +50), new Point(stop.X, stop.Y +50)) //圆的坐标 横轴坐标不变, 纵轴坐标+ - 50 //(pen,start.X-15,start.Y-15,30,30); (pen, start.X - 15, start.Y - 65, 30, 30); (pen, start.X - 15, start.Y + 35, 30, 30); g.DrawLine(pen,new Point (start.X,start.Y-50),new Point (stop.X,stop.Y-50)); g.DrawLine(pen, new Point(start.X, start.Y +50), new Point(stop.X, stop.Y +50)); timer1.Enabled = true; try { // Retrieve the image. image1 = new Bitmap(Application.StartupPath + @"/images/black.png", true); int x, y; // Loop through the images pixels to reset color. for (x = 0; x < image1.Width; x++) { for (y = 0; y < image1.Height; y++) { Color pixelColor = image1.GetPixel(x, y); Color newColor = Color.FromArgb(pixelColor.B, 0, 0); image1.SetPixel(x, y, newColor); } } // Set the PictureBox to display the image. pictureBox1.Image = image1; } catch (ArgumentException) { MessageBox.Show("There was an error." + "Check the path to the image file."); } this.BackgroundImage = null; this.BackgroundImage = bmp; } private void timer1_Tick(object sender, EventArgs e) { P_lo = pictureBox1.Location; P_lo = new Point(start.X, start.Y); P_lo.X ++; P_lo.Y ++; pictureBox1.Location = P_lo; } }}
查看完整描述

1 回答

?
森林海

TA贡献2011条经验 获得超2个赞

pictureBox1.Location = new Point(pictureBox1.Location.X + 1, pictureBox1.Location.Y + 1)
查看完整回答
反对 回复 2018-12-09
  • 1 回答
  • 0 关注
  • 514 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信