积极答复者
请问这个油罐液位监控的界面怎麽实现

问题
答案
-
您好,
你的那个镂空效果怎么做的?
理论上说,你可以通过shapeContainer的paint事件来做,如果你以上方案不行的话。
如果你能提供一个测试工程,我将非常乐意帮忙看看。
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Steven.桦仔 2012年12月25日 2:55
-
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Windows.Forms; namespace MonitorLevelMeter.LevelMeterUserControl { public partial class OilCan : UserControl { #region 全局变量 /// <summary> /// 控件油罐高度 /// </summary> private int _oilCanControlHeight; /// <summary> /// 控件油高 /// </summary> private int _oilControlHeight; /// <summary> /// 控件水高 /// </summary> private int _waterControlHeight; /// <summary> /// 油罐号 /// </summary> private int _oilCanNO; /// <summary> /// 油品 /// </summary> private string _oilType; /// <summary> /// 倾斜校正 /// </summary> private int _emendation; /// <summary> /// 最小容积 /// </summary> private int _leastCubage; /// <summary> /// 最大容积 /// </summary> private int _mostCubage; /// <summary> /// 报警水位 /// </summary> private int _warningPostion; /// <summary> /// 最低液位 /// </summary> private int _lowestPostion; /// <summary> /// 最高液位 /// </summary> private int _highestPostion; /// <summary> /// 油罐高度 /// </summary> private double _oilCanHeight; /// <summary> /// 油罐温度 /// </summary> private string _oilCanTemperature; /// <summary> /// 油高 /// </summary> private double _oilHeight; /// <summary> /// 水高 /// </summary> private double _waterHeight; #endregion public OilCan() { InitializeComponent(); } #region 公有属性 #endregion /// <summary> /// 油罐号 /// </summary> public int OilCanNo { get { return _oilCanNO; } set { _oilCanNO = value; } } /// <summary> /// 油品 /// </summary> public string OilType { get { return _oilType; } set { _oilType = value; } } /// <summary> /// 油罐高度 /// </summary> public double OilCanHeight { get { return _oilCanHeight; } set { _oilCanHeight = value; } } /// <summary> /// 倾斜校正 /// </summary> public int Emendation { get { return _emendation; } set { _emendation = value; } } /// <summary> /// 最小容积 /// </summary> public int LeastCubage { get { return _leastCubage; } set { _leastCubage = value; } } /// <summary> /// 最大容积 /// </summary> public int MostCubage { get { return _mostCubage; } set { _mostCubage = value; } } /// <summary> /// 报警水位 /// </summary> public int WarningPostion { get { return _warningPostion; } set { _warningPostion = value; } } /// <summary> /// 最低液位 /// </summary> public int LowestPostion { get { return _lowestPostion; } set { _lowestPostion = value; } } /// <summary> /// 最高液位 /// </summary> public int HighestPostion { get { return _highestPostion; } set { _highestPostion = value; } } /// <summary> /// 油高 /// </summary> public double OilHeight { get { return _oilHeight; } set { _oilHeight = value; double liquidHeigth = _oilHeight + _waterHeight; if (liquidHeigth > _oilCanHeight) { return; } if (_oilHeight < _oilCanHeight*0.01) { OilControlHeight = 0; return; } else { decimal result = Convert.ToDecimal(Math.Round(_oilHeight/_oilCanHeight, 2)); int st = Convert.ToInt32(result*_oilCanControlHeight); OilControlHeight = st; } } } /// <summary> /// 水高 /// </summary> public double WaterHeight { get { return _waterHeight; } set { _waterHeight = value; double liquidHeigth = _oilHeight + _waterHeight; if (liquidHeigth > _oilCanHeight) { return; } if (_waterHeight < _oilCanHeight*0.01) { WaterControlHeight = 0; return; } else { decimal result = Convert.ToDecimal(Math.Round(_waterHeight/_oilCanHeight, 2)); int st = Convert.ToInt32(result*_oilCanControlHeight); WaterControlHeight = st; } } } /// <summary> /// 控件油罐高度 /// </summary> public int OilCanControlHeight { get { return _oilCanControlHeight; } set { _oilCanControlHeight = value; } } /// <summary> /// 控件油高 /// </summary> public int OilControlHeight { get { return _oilControlHeight; } set { _oilControlHeight = value; int liquidHeigth = _oilControlHeight + _waterControlHeight; if (liquidHeigth > _oilCanControlHeight) { return; } if (_oilControlHeight == 0 && _waterControlHeight == 0) { pictureBox1.BackgroundImage = null; pictureBox2.BackgroundImage = null; pictureBox3.BackgroundImage = null; pictureBox4.BackgroundImage = null; pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandair.png"); } else if (_oilControlHeight > 0 && _waterControlHeight > 0) { pictureBox4.Height = 15; pictureBox2.Height = 15; pictureBox4.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oilandair.png"); pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\border.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandwater.png"); pictureBox3.Height = _oilControlHeight; pictureBox1.Height = _waterControlHeight; pictureBox3.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oil.png"); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\water.png"); } else if (_oilControlHeight > 0 && _waterControlHeight == 0) { pictureBox3.BackgroundImage = null; pictureBox4.BackgroundImage = null; pictureBox2.Height = 15; pictureBox1.Height = _oilControlHeight; pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oilandair.png"); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oil.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandoil.png"); } else if (_oilControlHeight == 0 && _waterControlHeight > 0) { pictureBox3.BackgroundImage = null; pictureBox4.BackgroundImage = null; pictureBox2.Height = 15; pictureBox1.Height = _waterControlHeight; pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\waterandair.png"); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\water.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandwater.png"); } } } /// <summary> /// 控件水高 /// </summary> public int WaterControlHeight { get { return _waterControlHeight; } set { _waterControlHeight = value; int liquidHeigth = _oilControlHeight + _waterControlHeight; if (liquidHeigth > _oilCanControlHeight) { return; } if (_oilControlHeight == 0 && _waterControlHeight == 0) { pictureBox1.BackgroundImage = null; pictureBox2.BackgroundImage = null; pictureBox3.BackgroundImage = null; pictureBox4.BackgroundImage = null; pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandair.png"); } else if (_oilControlHeight > 0 && _waterControlHeight > 0) { pictureBox4.Height = 15; pictureBox2.Height = 15; pictureBox4.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oilandair.png"); pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\border.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandwater.png"); pictureBox3.Height = _oilControlHeight; pictureBox1.Height = _waterControlHeight; pictureBox3.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oil.png"); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\water.png"); } else if (_oilControlHeight > 0 && _waterControlHeight == 0) { pictureBox3.BackgroundImage = null; pictureBox4.BackgroundImage = null; pictureBox2.Height = 15; pictureBox1.Height = _oilControlHeight; pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oilandair.png"); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oil.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandoil.png"); } else if (_oilControlHeight == 0 && _waterControlHeight > 0) { pictureBox3.BackgroundImage = null; pictureBox4.BackgroundImage = null; pictureBox2.Height = 15; pictureBox1.Height = _waterControlHeight; pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\waterandair.png"); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\water.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandwater.png"); } } } /// <summary> /// 油罐温度 /// </summary> public string OilCanTemperature { get { return _oilCanTemperature; } set { _oilCanTemperature = value; } } /// <summary> /// 油罐控件装载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OilCan_Load(object sender, EventArgs e) { //预留10个像素 来装载空隙,比如椭圆 this.Size = new Size(210, 410); sc_Bottom.SplitterDistance = 380; pictureBox4.Height = 15; pictureBox2.Height = 15; pictureBox4.BackgroundImage = null; pictureBox2.BackgroundImage = null; //设置油罐的头部 底部 和中间的高度 tlp_OilCan.RowStyles[0].SizeType = SizeType.Absolute; tlp_OilCan.RowStyles[1].SizeType = SizeType.Percent; tlp_OilCan.RowStyles[2].SizeType = SizeType.Absolute; tlp_OilCan.RowStyles[0].Height = 30; tlp_OilCan.RowStyles[2].Height = 20; pic_OilCanHead.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\head.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandair.png"); pl_OilCanMiddle.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\middle.png"); sc_Bottom.IsSplitterFixed = true; this._oilCanControlHeight = pl_OilCanMiddle.Height - 30; #region 把控件里的所有事件重定向到油罐控件本身 //MouseEnter事件 this.pl_OilCanMiddle.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); tlp_OilCan.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); pic_OilCanHead.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); pic_OilCanTail.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //pictureBox1.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //pictureBox2.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //pictureBox3.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //pictureBox4.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //lbl_OilCanNO.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //lbl_OilType.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //labelX1.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //labelX3.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //MouseLeave事件 this.pl_OilCanMiddle.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); tlp_OilCan.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); pic_OilCanHead.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); pic_OilCanTail.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //pictureBox1.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //pictureBox2.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //pictureBox3.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //pictureBox4.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //lbl_OilCanNO.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //lbl_OilType.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //labelX1.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //labelX3.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //MouseHover事件 this.pl_OilCanMiddle.MouseHover += new EventHandler(sc_Bottom_MouseHover); tlp_OilCan.MouseHover += new EventHandler(sc_Bottom_MouseHover); pic_OilCanHead.MouseHover += new EventHandler(sc_Bottom_MouseHover); pic_OilCanTail.MouseHover += new EventHandler(sc_Bottom_MouseHover); pictureBox1.MouseHover += new EventHandler(sc_Bottom_MouseHover); pictureBox2.MouseHover += new EventHandler(sc_Bottom_MouseHover); pictureBox3.MouseHover += new EventHandler(sc_Bottom_MouseHover); pictureBox4.MouseHover += new EventHandler(sc_Bottom_MouseHover); lbl_OilCanNO.MouseHover += new EventHandler(sc_Bottom_MouseHover); lbl_OilType.MouseHover += new EventHandler(sc_Bottom_MouseHover); labelX1.MouseHover += new EventHandler(sc_Bottom_MouseHover); labelX3.MouseHover += new EventHandler(sc_Bottom_MouseHover); #endregion } #region 重写事件 public new event EventHandler MouseEnter; public new event EventHandler MouseLeave; public new event EventHandler MouseHover; #endregion private void sc_Bottom_MouseEnter(object sender, EventArgs e) { if (MouseEnter != null) { MouseEnter(this, e); } } private void sc_Bottom_MouseLeave(object sender, EventArgs e) { if (MouseLeave != null) { MouseLeave(this, e); } } private void sc_Bottom_MouseHover(object sender, EventArgs e) { if (MouseHover != null) { MouseHover(this, e); } } } }
- 已建议为答案 Lisa ZhuModerator 2012年12月24日 8:20
- 已标记为答案 Steven.桦仔 2012年12月25日 2:55
全部回复
-
代码:
namespace WindowsFormsApplication1 { public partial class Form3 : Form { public Form3() { InitializeComponent(); shapeContainer1.Dock = DockStyle.Fill; //rectangleShape3.Size = shapeContainer3.Size; //shapeContainer3.Location = new Point(0, 0); label1.Size = new Size(rectangleShape1.Width - 8, rectangleShape1.Height); label1.Location = new Point(rectangleShape1.Location.X + 5, rectangleShape1.Location.Y); } private void button1_Click(object sender, EventArgs e) { int dd = label1.Location.Y; label1.Location = new Point(rectangleShape1.Location.X + 5, dd + 5); } } }
-
你好,
请问你是如何放置你的油罐图片的呢?用的panel?还是rectangleShape1?
对于你的描述,我有几个不明白的地方,希望你可以详细解释一下:
1.在一楼, 你说需要两个panel代表水位和油位,可是你的代码中并没有panel出现。为什么?
2.据我猜测,你是用的label来代表的水位,控制其坐标来实现上下移动。你到底是想用label还是panel呢?
3.油位和水位有什么关系吗?会同时出现在油罐中吗?
4.rectangleShape1是用来控制什么的?
我只是用的普通图片测试一下,所以如果设置panel背景图片为油罐的话,水位是可以上下移动,且油罐不会移动。如果不对的话,可否提供你的油罐图片呢?
谢谢。
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
您好,
你的那个镂空效果怎么做的?
理论上说,你可以通过shapeContainer的paint事件来做,如果你以上方案不行的话。
如果你能提供一个测试工程,我将非常乐意帮忙看看。
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Steven.桦仔 2012年12月25日 2:55
-
楼主,
我根据你提供的信息, 做了个模型, 你瞧瞧:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.ovalShape1.BringToFront(); } private void ovalShape1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; OvalShape osh = (OvalShape)sender; // Create a GraphicsPath object. GraphicsPath myPath = new GraphicsPath(); // Set up and call AddArc, and close the figure. Rectangle rect = new Rectangle(osh.Location.X, osh.Location.Y, osh.DisplayRectangle.Width, osh.DisplayRectangle.Height); myPath.StartFigure(); myPath.AddArc(rect, 270 + Offset, 360 - 2 * Offset); myPath.CloseFigure(); g.FillRegion(Brushes.Green, new Region(myPath)); } private int Offset = 0; private void button1_Click(object sender, EventArgs e) { Offset += 10; if (Offset <= 180) { this.label1.Text = "Offset: " + Offset; ovalShape1.Invalidate(); } } }
效果图:
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
- 已建议为答案 Mike FengModerator 2012年12月24日 1:42
- 取消建议作为答案 Mike FengModerator 2012年12月24日 8:35
-
嗯,看着 挺漂亮。
能共享下你怎么做的吗?谢谢
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 Mike FengModerator 2012年12月21日 15:34
-
OK, 我猜想你是不同的pictureBox里面放置不同的图片显示不同的效果,现在你应该是想移动黄色区域来显示不同的油量水位吧,而你的黄色区域块也是在一个picturebox里面的,然后你现在的做法是移动这个picturebox的位置即 location属性,而且你已经实现了,对吧??
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
- 已建议为答案 Mike FengModerator 2012年12月24日 1:42
- 取消建议作为答案 Mike FengModerator 2012年12月24日 8:35
-
好 等你好消息咯
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
- 已编辑 Steven.桦仔 2012年12月22日 2:37
- 已建议为答案 Mike FengModerator 2012年12月24日 1:42
- 取消建议作为答案 Mike FengModerator 2012年12月24日 8:35
-
谢谢你的update。
从你的回复来看,其实你一直都知道应该怎么做的,而且一直在分享着你的思路。非常感谢!
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Windows.Forms; namespace MonitorLevelMeter.LevelMeterUserControl { public partial class OilCan : UserControl { #region 全局变量 /// <summary> /// 控件油罐高度 /// </summary> private int _oilCanControlHeight; /// <summary> /// 控件油高 /// </summary> private int _oilControlHeight; /// <summary> /// 控件水高 /// </summary> private int _waterControlHeight; /// <summary> /// 油罐号 /// </summary> private int _oilCanNO; /// <summary> /// 油品 /// </summary> private string _oilType; /// <summary> /// 倾斜校正 /// </summary> private int _emendation; /// <summary> /// 最小容积 /// </summary> private int _leastCubage; /// <summary> /// 最大容积 /// </summary> private int _mostCubage; /// <summary> /// 报警水位 /// </summary> private int _warningPostion; /// <summary> /// 最低液位 /// </summary> private int _lowestPostion; /// <summary> /// 最高液位 /// </summary> private int _highestPostion; /// <summary> /// 油罐高度 /// </summary> private double _oilCanHeight; /// <summary> /// 油罐温度 /// </summary> private string _oilCanTemperature; /// <summary> /// 油高 /// </summary> private double _oilHeight; /// <summary> /// 水高 /// </summary> private double _waterHeight; #endregion public OilCan() { InitializeComponent(); } #region 公有属性 #endregion /// <summary> /// 油罐号 /// </summary> public int OilCanNo { get { return _oilCanNO; } set { _oilCanNO = value; } } /// <summary> /// 油品 /// </summary> public string OilType { get { return _oilType; } set { _oilType = value; } } /// <summary> /// 油罐高度 /// </summary> public double OilCanHeight { get { return _oilCanHeight; } set { _oilCanHeight = value; } } /// <summary> /// 倾斜校正 /// </summary> public int Emendation { get { return _emendation; } set { _emendation = value; } } /// <summary> /// 最小容积 /// </summary> public int LeastCubage { get { return _leastCubage; } set { _leastCubage = value; } } /// <summary> /// 最大容积 /// </summary> public int MostCubage { get { return _mostCubage; } set { _mostCubage = value; } } /// <summary> /// 报警水位 /// </summary> public int WarningPostion { get { return _warningPostion; } set { _warningPostion = value; } } /// <summary> /// 最低液位 /// </summary> public int LowestPostion { get { return _lowestPostion; } set { _lowestPostion = value; } } /// <summary> /// 最高液位 /// </summary> public int HighestPostion { get { return _highestPostion; } set { _highestPostion = value; } } /// <summary> /// 油高 /// </summary> public double OilHeight { get { return _oilHeight; } set { _oilHeight = value; double liquidHeigth = _oilHeight + _waterHeight; if (liquidHeigth > _oilCanHeight) { return; } if (_oilHeight < _oilCanHeight*0.01) { OilControlHeight = 0; return; } else { decimal result = Convert.ToDecimal(Math.Round(_oilHeight/_oilCanHeight, 2)); int st = Convert.ToInt32(result*_oilCanControlHeight); OilControlHeight = st; } } } /// <summary> /// 水高 /// </summary> public double WaterHeight { get { return _waterHeight; } set { _waterHeight = value; double liquidHeigth = _oilHeight + _waterHeight; if (liquidHeigth > _oilCanHeight) { return; } if (_waterHeight < _oilCanHeight*0.01) { WaterControlHeight = 0; return; } else { decimal result = Convert.ToDecimal(Math.Round(_waterHeight/_oilCanHeight, 2)); int st = Convert.ToInt32(result*_oilCanControlHeight); WaterControlHeight = st; } } } /// <summary> /// 控件油罐高度 /// </summary> public int OilCanControlHeight { get { return _oilCanControlHeight; } set { _oilCanControlHeight = value; } } /// <summary> /// 控件油高 /// </summary> public int OilControlHeight { get { return _oilControlHeight; } set { _oilControlHeight = value; int liquidHeigth = _oilControlHeight + _waterControlHeight; if (liquidHeigth > _oilCanControlHeight) { return; } if (_oilControlHeight == 0 && _waterControlHeight == 0) { pictureBox1.BackgroundImage = null; pictureBox2.BackgroundImage = null; pictureBox3.BackgroundImage = null; pictureBox4.BackgroundImage = null; pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandair.png"); } else if (_oilControlHeight > 0 && _waterControlHeight > 0) { pictureBox4.Height = 15; pictureBox2.Height = 15; pictureBox4.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oilandair.png"); pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\border.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandwater.png"); pictureBox3.Height = _oilControlHeight; pictureBox1.Height = _waterControlHeight; pictureBox3.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oil.png"); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\water.png"); } else if (_oilControlHeight > 0 && _waterControlHeight == 0) { pictureBox3.BackgroundImage = null; pictureBox4.BackgroundImage = null; pictureBox2.Height = 15; pictureBox1.Height = _oilControlHeight; pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oilandair.png"); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oil.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandoil.png"); } else if (_oilControlHeight == 0 && _waterControlHeight > 0) { pictureBox3.BackgroundImage = null; pictureBox4.BackgroundImage = null; pictureBox2.Height = 15; pictureBox1.Height = _waterControlHeight; pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\waterandair.png"); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\water.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandwater.png"); } } } /// <summary> /// 控件水高 /// </summary> public int WaterControlHeight { get { return _waterControlHeight; } set { _waterControlHeight = value; int liquidHeigth = _oilControlHeight + _waterControlHeight; if (liquidHeigth > _oilCanControlHeight) { return; } if (_oilControlHeight == 0 && _waterControlHeight == 0) { pictureBox1.BackgroundImage = null; pictureBox2.BackgroundImage = null; pictureBox3.BackgroundImage = null; pictureBox4.BackgroundImage = null; pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandair.png"); } else if (_oilControlHeight > 0 && _waterControlHeight > 0) { pictureBox4.Height = 15; pictureBox2.Height = 15; pictureBox4.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oilandair.png"); pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\border.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandwater.png"); pictureBox3.Height = _oilControlHeight; pictureBox1.Height = _waterControlHeight; pictureBox3.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oil.png"); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\water.png"); } else if (_oilControlHeight > 0 && _waterControlHeight == 0) { pictureBox3.BackgroundImage = null; pictureBox4.BackgroundImage = null; pictureBox2.Height = 15; pictureBox1.Height = _oilControlHeight; pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oilandair.png"); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\oil.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandoil.png"); } else if (_oilControlHeight == 0 && _waterControlHeight > 0) { pictureBox3.BackgroundImage = null; pictureBox4.BackgroundImage = null; pictureBox2.Height = 15; pictureBox1.Height = _waterControlHeight; pictureBox2.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\waterandair.png"); pictureBox1.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\water.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandwater.png"); } } } /// <summary> /// 油罐温度 /// </summary> public string OilCanTemperature { get { return _oilCanTemperature; } set { _oilCanTemperature = value; } } /// <summary> /// 油罐控件装载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OilCan_Load(object sender, EventArgs e) { //预留10个像素 来装载空隙,比如椭圆 this.Size = new Size(210, 410); sc_Bottom.SplitterDistance = 380; pictureBox4.Height = 15; pictureBox2.Height = 15; pictureBox4.BackgroundImage = null; pictureBox2.BackgroundImage = null; //设置油罐的头部 底部 和中间的高度 tlp_OilCan.RowStyles[0].SizeType = SizeType.Absolute; tlp_OilCan.RowStyles[1].SizeType = SizeType.Percent; tlp_OilCan.RowStyles[2].SizeType = SizeType.Absolute; tlp_OilCan.RowStyles[0].Height = 30; tlp_OilCan.RowStyles[2].Height = 20; pic_OilCanHead.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\head.png"); pic_OilCanTail.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\bottomandair.png"); pl_OilCanMiddle.BackgroundImage = Image.FromFile(Application.StartupPath + @"\images\middle.png"); sc_Bottom.IsSplitterFixed = true; this._oilCanControlHeight = pl_OilCanMiddle.Height - 30; #region 把控件里的所有事件重定向到油罐控件本身 //MouseEnter事件 this.pl_OilCanMiddle.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); tlp_OilCan.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); pic_OilCanHead.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); pic_OilCanTail.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //pictureBox1.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //pictureBox2.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //pictureBox3.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //pictureBox4.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //lbl_OilCanNO.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //lbl_OilType.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //labelX1.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //labelX3.MouseEnter += new EventHandler(sc_Bottom_MouseEnter); //MouseLeave事件 this.pl_OilCanMiddle.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); tlp_OilCan.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); pic_OilCanHead.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); pic_OilCanTail.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //pictureBox1.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //pictureBox2.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //pictureBox3.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //pictureBox4.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //lbl_OilCanNO.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //lbl_OilType.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //labelX1.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //labelX3.MouseLeave += new EventHandler(sc_Bottom_MouseLeave); //MouseHover事件 this.pl_OilCanMiddle.MouseHover += new EventHandler(sc_Bottom_MouseHover); tlp_OilCan.MouseHover += new EventHandler(sc_Bottom_MouseHover); pic_OilCanHead.MouseHover += new EventHandler(sc_Bottom_MouseHover); pic_OilCanTail.MouseHover += new EventHandler(sc_Bottom_MouseHover); pictureBox1.MouseHover += new EventHandler(sc_Bottom_MouseHover); pictureBox2.MouseHover += new EventHandler(sc_Bottom_MouseHover); pictureBox3.MouseHover += new EventHandler(sc_Bottom_MouseHover); pictureBox4.MouseHover += new EventHandler(sc_Bottom_MouseHover); lbl_OilCanNO.MouseHover += new EventHandler(sc_Bottom_MouseHover); lbl_OilType.MouseHover += new EventHandler(sc_Bottom_MouseHover); labelX1.MouseHover += new EventHandler(sc_Bottom_MouseHover); labelX3.MouseHover += new EventHandler(sc_Bottom_MouseHover); #endregion } #region 重写事件 public new event EventHandler MouseEnter; public new event EventHandler MouseLeave; public new event EventHandler MouseHover; #endregion private void sc_Bottom_MouseEnter(object sender, EventArgs e) { if (MouseEnter != null) { MouseEnter(this, e); } } private void sc_Bottom_MouseLeave(object sender, EventArgs e) { if (MouseLeave != null) { MouseLeave(this, e); } } private void sc_Bottom_MouseHover(object sender, EventArgs e) { if (MouseHover != null) { MouseHover(this, e); } } } }
- 已建议为答案 Lisa ZhuModerator 2012年12月24日 8:20
- 已标记为答案 Steven.桦仔 2012年12月25日 2:55