111,126
社区成员
发帖
与我相关
我的任务
分享
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Bitmap backImage = null;
private Timer tmr = null;
private Int32 h = 0;
public Form1()
{
InitializeComponent();
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.FormBorderStyle = FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
this.MinimizeBox = false;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "bmp,jpg|*.bmp;*.jpg";
if (ofd.ShowDialog() == DialogResult.OK)
{
backImage =(Bitmap ) Image.FromFile(ofd.FileName);
this.Size = backImage.Size;
tmr = new Timer();
tmr.Tick += tmrTick;
tmr.Interval = 10;
tmr.Start();
}
else
{
this.Close();
}
}
private void tmrTick(object sender, EventArgs e)
{
if (backImage != null)
{
using (Bitmap img = new Bitmap(this.Width, this.Height))
{
using (Graphics g = Graphics.FromImage(img))
{
g.DrawImage(backImage, new Rectangle(0, h, this.Width, this.Height - h), 0, 0, backImage.Width, backImage.Height - h, GraphicsUnit.Pixel);
h += 1;
if (h < this.Height) g.DrawImage(backImage, new Rectangle(0, 0, this.Width, h), 0, backImage.Height - h, backImage.Width, h, GraphicsUnit.Pixel); else h = 0;
}
this.CreateGraphics().DrawImage(img, 0, 0);
}
}
}
}
}
Public Class Form1
Private backImage As Bitmap = Nothing
Private tmr As Timer = Nothing
Private h As Integer
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If tmr IsNot Nothing Then tmr.Stop()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Fixed3D
Me.MaximizeBox = False
Me.MinimizeBox = False
Dim ofd As New OpenFileDialog
ofd.Filter = "bmp,jpg|*.bmp;*.jpg"
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
backImage = Image.FromFile(ofd.FileName)
Me.Size = backImage.Size
tmr = New Timer
AddHandler tmr.Tick, AddressOf tmrTick
tmr.Interval = 10
tmr.Start()
Else
Me.Close()
End If
End Sub
Private Sub tmrTick(ByVal sender As Object, ByVal e As EventArgs)
If backImage IsNot Nothing Then
Using img As New Bitmap(Me.Width, Me.Height)
Using g As Graphics = Graphics.FromImage(img)
g.DrawImage(backImage, New Rectangle(0, h, Me.Width, Me.Height - h), 0, 0, backImage.Width, backImage.Height - h, GraphicsUnit.Pixel)
h += 1
If h < Me.Height Then g.DrawImage(backImage, New Rectangle(0, 0, Me.Width, h), 0, backImage.Height - h, backImage.Width, h, GraphicsUnit.Pixel) Else h = 0
End Using
Me.CreateGraphics.DrawImage(img, 0, 0)
End Using
End If
End Sub
End Class