Exemplo n.º 1
0
        private void btnSetAndAcquire_Click(object sender, System.EventArgs e)
        {
            float fFrameLeft, fFrameTop, fFrameRight, fFrameBottom, frameTemp;

            try
            {
                fFrameLeft   = Convert.ToSingle(edtFrameLeft.Text);
                fFrameTop    = Convert.ToSingle(edtFrameTop.Text);
                fFrameRight  = Convert.ToSingle(edtFrameRight.Text);
                fFrameBottom = Convert.ToSingle(edtFrameBottom.Text);

                if (fFrameLeft > fFrameRight)
                {
                    frameTemp   = fFrameLeft;
                    fFrameLeft  = fFrameRight;
                    fFrameRight = frameTemp;
                }

                if (fFrameTop > fFrameBottom)
                {
                    frameTemp    = fFrameTop;
                    fFrameTop    = fFrameBottom;
                    fFrameBottom = frameTemp;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please input numerical values in the input boxes.", "Error");
                return;
            }

            if (fFrameLeft == fFrameRight || fFrameTop == fFrameBottom)
            {
                MessageBox.Show("Input Value Error: don't make left equal to right, or top equal to bottom.", "Error");
                return;
            }
            if (fFrameLeft < fDefaultFrameLeft || fFrameTop < fDefaultFrameTop || fFrameRight > fDefaultFrameRight || fFrameBottom > fDefaultFrameBottom)
            {
                DialogResult drImageLayout = MessageBox.Show("Input values are out of rangles,do you want to continue?", "Warning", MessageBoxButtons.YesNo);
                if (drImageLayout == System.Windows.Forms.DialogResult.Yes)
                {
                }
                else
                {
                    return;
                }
            }
            if (m_TwainManager.SetImageLayout(new Margin(fFrameLeft, fFrameTop, fFrameRight, fFrameBottom)) == false)
            {
                MessageBox.Show("Fail to set image layout", "Error");
            }
            else
            {
                m_TwainManager.IfShowUI = false;

                m_TwainManager.IfDisableSourceAfterAcquire = true;
                m_TwainManager.EnableSource(this as IAcquireCallback);
            }
        }