using System; using System.Drawing; using System.IO; using System.Reflection; using System.Windows.Forms; namespace Mesnac.Controls.Feeding { /// /// 弯管 /// [ToolboxBitmap( typeof( BentTube ) , "ICONS.BentTube.bmp" )]//新添加的代码 public partial class BentTube : FeedingControl { bool bNewPic = false; public enum Types { wtLeftDown = 0, wtLeftTop = 1, wtRightTop = 2, wtRightDown = 3 } Types _type; string []sImages; public BentTube() : base() { InitializeComponent(); Init(); ReloadStream(); } protected override void Init() { base.Init(); _imageStream = null; sImages = new string[4]; sImages[0] = "Mesnac.Controls.Feeding.Resources.wg.WGTp1.png";//dkNull sImages[1] = "Mesnac.Controls.Feeding.Resources.wg.WGTp3.png";//dkNull sImages[2] = "Mesnac.Controls.Feeding.Resources.wg.WGTp0.png";//dkNull sImages[3] = "Mesnac.Controls.Feeding.Resources.wg.WGTp2.png";//dkNull _type = Types.wtLeftDown; } private void ReloadStream() { //CloseStream(); int nIndex = (int)_type; _imageStream = _assembly.GetManifestResourceStream(sImages[nIndex]); } public Types Type { get { return _type; } set { if (bFirstCreated == true) { bFirstCreated = false; } if (_type != value) { if (this.DesignMode == true) { bNewPic = true; } } _type = value; ReloadStream(); this.Refresh(); } } protected override void OnPaint(PaintEventArgs e) { if (_imageStream != null) { Graphics g = e.Graphics; Image img = Image.FromStream(_imageStream); //if (_type == Types.wtLeftDown) //{ // //img.RotateFlip(RotateFlipType. //} //else if (_type == Types.wtLeftTop) //{ // img.RotateFlip(RotateFlipType.RotateNoneFlipY); //} //else if (_type == Types.wtRightTop) //{ // img.RotateFlip(RotateFlipType.RotateNoneFlipXY); //} //else if (_type == Types.wtRightDown) //{ // img.RotateFlip(RotateFlipType.RotateNoneFlipX); //} if (bNewPic == true) { this.Size = img.Size; bNewPic = false; } g.DrawImage(img, 0, 0, this.Width, this.Height); } } private void BentTube_Load(object sender, EventArgs e) { if (bFirstCreated == true && this.DesignMode == true) { bNewPic = true; bFirstCreated = false; } } } }