The control code is as follows:
using System;
using System.Collections.Generic;
Using System.Com ponentModel;
Using System. Drawing;
Using System. The Data;
Using System. Linq;
Using System. The Text;
Using System. Windows. Forms;
The namespace WindowsFormsControlLibrary2
{
Public enum WATER_STATE {Stop, In, Out};
Public enum ROTATE_STATE {Stop, ForwardRotating ReversaRotating};
Public partial class UserControl1: UserControl
{
Public UserControl1 ()
{
InitializeComponent();
DoubleBuffered=true;
SetStyle (ControlStyles. OptimizedDoubleBuffer |
ControlStyles. ResizeRedraw |
ControlStyles. AllPaintingInWmPaint, true);
}
Private double waterLevel.
Public double WaterLevel
{
The get {return waterLevel; }
The set {waterLevel=value; Enclosing the Refresh (); }
}
Public WATER_STATE waterState;
Public WATER_STATE WaterState
{
The get {return waterState; }
The set {waterState=value; Enclosing the Refresh (); }
}
Public ROTATE_STATE rotateState;
Public ROTATE_STATE RotateState
{
The get {return rotateState; }
The set {rotateState=value; Enclosing the Refresh (); }
}
Float Angle;
Public float Angle
{
The get {return Angle; }
The set {Angle=value; }
}
Float rotateSpd=3;
Public float RotateSpd
{
The get {return rotateSpd; }
The set {rotateSpd=value; }
}
Private void UserControl1_Paint (object sender, PaintEventArgs e)
{
//picture frame
Graphics g=um participant raphics;
G.D rawRectangle (new Pen (Color Black, 3), and 0, 3, enclosing Width 3, enclosing Height);
//draw change of water level
Int waterHeight=(int) (waterLevel/100.0 * this. Height);
A Rectangle waterRect=new Rectangle (2, enclosing Height - waterHeight - 4, enclosing the Width to 6, waterHeight);
G.F illRectangle (Brushes, SkyBlue, waterRect);
//draw rotating drum
Image imgFans=Properties. Resources. Fans3;
Int xPos=(enclosing Width - imgFans. Width)/2;
Int yPos=(. This Height - imgFans. Height)/2;
Point imgRotateCenterPos=new Point (imgFans. Width/2, imgFans Height/2);//center of rotation in image coordinates (relative to the image itself)
A Rectangle rcShow=new Rectangle (xPos, yPos, imgFans. Width, imgFans Height);//pictures to map the location of the area.
//pictures of relative to the center of rotation of the coordinate transformation for the paint area coordinates
PointF centerPos=new Point (imgRotateCenterPos. X + rcShow. Left, imgRotateCenterPos. Y + rcShow. Top);
G.T ranslateTransform (centerPos. X, centerPos. Y);//source point move to the center of rotation
G.R otateTransform (Angle);//rotate
G.T ranslateTransform - centerPos. X - centerPos. (Y);//restore source point
//display images in a starting point to
G.D rawImage (imgFans, rcShow. Left, rcShow. Top rcShow. Width, rcShow, Height);
}
Private void timer1_Tick (object sender, EventArgs e)
{
If (WaterState==WATER_STATE. In)
{
If (WaterLevel & gt;=80.0)
{
WaterState=WATER_STATE. Stop;
}
The else
WaterLevel +=0.1;
}
If (WaterState==WATER_STATE. Out)
{
If (waterLevel & gt; 0)
{
WaterLevel -=0.1;
}
The else
WaterState=WATER_STATE. Stop;
}
If (RotateState==ROTATE_STATE. ForwardRotating & amp; & ((WaterState==WATER_STATE. In) | | (WaterState==WATER_STATE. Out | | (WaterState==WATER_STATE. Stop))))
{
Angle +=rotateSpd;
}
If (RotateState==ROTATE_STATE. ReversaRotating & amp; & ((WaterState==WATER_STATE. In) | | (WaterState==WATER_STATE. Out) | | (WaterState==WATER_STATE. Stop)))
{
Angle -=rotateSpd;
}
}
Private void UserControl1_Load (object sender, EventArgs e)
{
}
}
}
CodePudding user response:
What is the time interval timer1_Tick, open have no?CodePudding user response:
The code is too much,If you use a map animation to wf image, or GIF does not support, need to use other ways,
Recommend you use WPF will be better,
CodePudding user response: