您的位置:首页 > 编程语言 > C#

最近的c#练习题目

2008-11-12 21:21 253 查看
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
int border = 50;
int x = e.X;
int y = e.Y;
int left = button1.Left;
int right = button1.Right;
int top = button1.Top;
int bottom = button1.Bottom;
if (x > left - border && x < right + border && y > top - border && y < bottom + border)
{
button1.Top += (y > top ? -20 : 20);
if (button1.Top >Form1.ActiveForm.Size.Height || button1.Bottom < 0)
{
button1 .Top =Form1 .ActiveForm .Size .Height /2;
}
button1.Left += (x > left ? -20 : 20);
if (button1.Left > Form1.ActiveForm.Size.Width || button1.Right < 0)
{
button1.Left = Form1.ActiveForm.Size.Width / 2;
}
}

绘制背景
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 WindowsFormsApplication31
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Color fcolor = Color.Yellow;
Color tcolor = Color.Red;
Brush b = new LinearGradientBrush(this.ClientRectangle, fcolor, tcolor, LinearGradientMode.ForwardDiagonal);
g.FillRectangle(b, this.ClientRectangle );
}

private void Form1_Resize(object sender, EventArgs e)
{
this.Invalidate();
}
}
}

中的lineargradientbrush方法的使用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: