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);
            }
        }
        private void btnAcquire_Click(object sender, System.EventArgs e)
        {
            if (dlgFileSave.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            strFileName = dlgFileSave.FileName;

            m_TwainManager.OpenSource();

            try
            {
                m_TwainManager.TransferMode = Dynamsoft.TWAIN.Enums.TWICapSetupXFer.TWSX_FILE;
            }
            catch (Exception exp)
            {
                MessageBox.Show("The license for TWAIN module is invalid.Please contact [email protected] to get a trial license.");
                return;
            }


            //Since the TWSX_FILE mode is not required by TWAIN specification,
            //it is better to read the value back to see if the File transfer mode is supported by the Source
            if (m_TwainManager.TransferMode == Dynamsoft.TWAIN.Enums.TWICapSetupXFer.TWSX_FILE)
            {                                                                                                 //the source supports the TWSX_FILE transfer mode.
                m_TwainManager.SetFileXFERInfo(strFileName, Dynamsoft.TWAIN.Enums.TWICapFileFormat.TWFF_BMP); //Sets file name and file format information.
                m_TwainManager.IfShowUI = false;
                m_TwainManager.IfDisableSourceAfterAcquire = true;
                m_TwainManager.EnableSource(this as IAcquireCallback); //Acquire the image.
            }
            else                                                       //the source doesn't support the TWSX_FILE transfer mode.
            {
                MessageBox.Show("The source doesn't support the DiskFile transfer mode.");
            }
        }