最近的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方法的使用
{
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方法的使用
相关文章推荐
- LeetCode Online Judge 题目C# 练习 - Valid Parentheses
- LeetCode Online Judge 题目C# 练习 - Search a 2D Matrix
- LeetCode Online Judge 题目C# 练习 - 3SUM
- LeetCode Online Judge 题目C# 练习 - Sparial Matrix II
- LeetCode Online Judge 题目C# 练习 - Swap Nodes in Pairs
- LeetCode Online Judge 题目C# 练习 - Longest Common Prefix
- LeetCode Online Judge 题目C# 练习 - Longest Substring Without Repeating Characters
- LeetCode Online Judge 题目C# 练习 - Merge Sorted Array
- LeetCode Online Judge 题目C# 练习 - Minimum Path Sum
- 【编程练习】最近准备开始找工作,这篇文章作为一个code练手题目的总结吧
- LeetCode Online Judge 题目C# 练习 - Reverse Linked List II
- LeetCode Online Judge 题目C# 练习 - Container With Most Water
- LeetCode Online Judge 题目C# 练习 - Two Sum
- LeetCode Online Judge 题目C# 练习 - Valid Sudoku
- LeetCode Online Judge 题目C# 练习 - Combination Sum
- LeetCode Online Judge 题目C# 练习 - Combination
- LeetCode Online Judge 题目C# 练习 - Restore IP Addresses
- LeetCode Online Judge 题目C# 练习 - Search in Rotated Sorted Array
- LeetCode Online Judge 题目C# 练习 - Simplify Path
- LeetCode Online Judge 题目C# 练习 - Longest Palindromic Substring