110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
BufferedGraphics grafx;
public Form1()
{
InitializeComponent();
this.MouseDoubleClick += new MouseEventHandler(Form1_MouseDoubleClick);
this.Load += new EventHandler(Form1_Load);
this.Paint += new PaintEventHandler(Form1_Paint);
}
void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Controls.Clear();
if (e.Button == MouseButtons.Left)
{
for (int i = 0; i < 1000; i += 100)
{
for (int j = 30; j < 800; j += 100)
{
Button button = new Button();
button.Location = new Point(i, j);
button.Size = new Size(80, 80);
button.BackColor = Color.Red;
this.Controls.Add(button);
}
}
}
}
Button addButton = new Button();
void Form1_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
BufferedGraphicsContext context = BufferedGraphicsManager.Current;
context.MaximumBuffer = new Size(this.Width, this.Height);
grafx = context.Allocate(this.CreateGraphics(), new Rectangle(0, 0, this.Width, this.Height));
DrawToBuffer(grafx.Graphics);
}
void Form1_Paint(object sender, PaintEventArgs e)
{
grafx.Render(e.Graphics);
}
void DrawToBuffer(Graphics g)
{
Image image = Image.FromFile(@"D:\MyImage.jpg");
g.DrawImage(image, 0, 0, this.Width, this.Height);
}
}
}