Пример #1
0
 void _allocImage()
 {
     if (mContext == null)
     {
         mContext = CustomGraphics.FromImage(BoundingBox.Width, BoundingBox.Height);
     }
 }
        public void CreateDialog()
        {
            InitializeComponent();

            mPnlV          = new Panel();
            mPnlV.AutoSize = true;

            mCanvas = new PictureBox()
            {
                Width = 320, Height = 320
            };
            mBmp = new Bitmap(mCanvas.Width, mCanvas.Height);
            mG   = CustomGraphics.FromImage(mBmp);
            mPnlV.Controls.Add(mCanvas);

            mChip      = new CustomCompositeChipElm(new Point(50, 50));
            mChip.P2.X = 200;
            mChip.P2.Y = 50;
            createPinsFromModel();

            var lbl = new Label()
            {
                Top = mCanvas.Bottom, AutoSize = true, Text = "Model Name"
            };

            mPnlV.Controls.Add(lbl);
            mModelNameTextBox = new TextBox()
            {
                Top = lbl.Bottom
            };
            mModelNameTextBox.Enabled = string.IsNullOrEmpty(mModel.Name);
            mModelNameTextBox.Text    = mModel.Name;
            mPnlV.Controls.Add(mModelNameTextBox);

            var pnlSize = new Panel();
            {
                pnlSize.Top      = mModelNameTextBox.Bottom;
                pnlSize.AutoSize = true;
                int ofsY = 0;
                var lblW = new Label()
                {
                    Top = ofsY, AutoSize = true, Text = "Width"
                };
                pnlSize.Controls.Add(lblW);
                ofsY += lblW.Height;
                /* Width+ */
                var bwp = new Button()
                {
                    Top = ofsY, Width = 40, Text = "+"
                };
                bwp.Click += new EventHandler((s, e) => {
                    adjustChipSize(1, 0);
                });
                pnlSize.Controls.Add(bwp);
                /* Width- */
                var bwm = new Button()
                {
                    Top = ofsY, Width = 40, Left = bwp.Right + 4, Text = "-"
                };
                bwm.Click += new EventHandler((s, e) => {
                    adjustChipSize(-1, 0);
                });
                pnlSize.Controls.Add(bwm);
                ofsY += bwm.Height + 4;

                var lblH = new Label()
                {
                    Top = ofsY, AutoSize = true, Text = "Height"
                };
                pnlSize.Controls.Add(lblH);
                ofsY += lblH.Height;
                /* Height+ */
                var bhp = new Button()
                {
                    Top = ofsY, Width = 40, Text = "+"
                };
                bhp.Click += new EventHandler((s, e) => {
                    adjustChipSize(0, 1);
                });
                pnlSize.Controls.Add(bhp);
                /* Height- */
                var bhm = new Button()
                {
                    Top = ofsY, Width = 40, Left = bhp.Right + 4, Text = "-"
                };
                bhm.Click += new EventHandler((s, e) => {
                    adjustChipSize(0, -1);
                });
                pnlSize.Controls.Add(bhm);
                /* */
                mPnlV.Controls.Add(pnlSize);
            }

            var pnlButton = new Panel();

            {
                pnlButton.Top      = pnlSize.Bottom;
                pnlButton.AutoSize = true;
                /* OK */
                var okButton = new Button()
                {
                    Text = "OK"
                };
                okButton.Click += new EventHandler((s, e) => {
                    if (mModelNameTextBox != null)
                    {
                        string name = mModelNameTextBox.Text;
                        if (name.Length == 0)
                        {
                            MessageBox.Show("Please enter a model name.");
                            return;
                        }
                        mModel.SetName(CustomCompositeElm.lastModelName = name);
                    }
                    CirSim.Sim.UpdateModels();
                    CirSim.Sim.NeedAnalyze(); /* will get singular matrix if we don't do this */
                    closeDialog();
                });
                pnlButton.Controls.Add(okButton);
                /* */
                mPnlV.Controls.Add(pnlButton);
            }

            mCanvas.MouseDown += new MouseEventHandler((s, e) => { onMouseDown(e); });
            mCanvas.MouseUp   += new MouseEventHandler((s, e) => { onMouseUp(e); });
            mCanvas.MouseMove += new MouseEventHandler((s, e) => { onMouseMove(e); });

            Controls.Add(mPnlV);

            Width  = mCanvas.Width + 16;
            Height = pnlButton.Bottom;

            timer1.Interval = 33;
            timer1.Enabled  = true;
            timer1.Start();
        }