Leadtools TWAIN(Leadtools.Twainアセンブリ)

フレームを表示

TwainExceptionクラス






メンバ 
TWAINエラーが発生するとき、スローされる例外。
オブジェクトモデル
構文
解説

TwainExceptionクラスは、何がエラーを引き起こしたか決定するために調べることができるCodeプロパティを定義します。

デフォルトのメッセージは各々のCodeのために実装されます、しかしGetCodeMessageSetCodeMessageメソッドを通して任意のメッセージを修正することができます。

サンプル
Copy Code  
Imports Leadtools
      Imports Leadtools.Twain

      Public Sub _twainSession_AcquirePage(ByVal sender As Object, ByVal e As TwainAcquirePageEventArgs)
         Application.DoEvents()
         If Not e.Image Is Nothing Then
            e.Image.Dispose()
         End If

         e.Cancel = False
      End Sub


#If Not LEADTOOLS_V19_OR_LATER Then
      Public Sub TwainExceptionExample(ByVal parent As IWin32Window)
#Else
      Public Sub TwainExceptionExample(ByVal parent As IntPtr)
#End If ' #If LEADTOOLS_V19_OR_LATER Then
         Dim session As TwainSession = Nothing

         Try
            ' initialize a new TWAIN session
            session = New TwainSession()
            session.Startup(parent, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None)
            AddHandler session.AcquirePage, AddressOf _twainSession_AcquirePage

            ' acquire a page, if paper jam, allow the user to retry
            Dim done As Boolean = False
            Do While Not done
               Try
                  Dim res As DialogResult = session.Acquire(TwainUserInterfaceFlags.Modal Or TwainUserInterfaceFlags.Show)
                  MessageBox.Show("Success")
                  done = True
               Catch ex As TwainException
                  If ex.Code = TwainExceptionCode.PaperJam Then
                     If MessageBox.Show("Paper jam.  Fix and retry?", "TWAIN", MessageBoxButtons.YesNo) = DialogResult.No Then
                        done = True
                     End If
                  Else
                     ' other error, propogate
                     Throw ex
                  End If
               End Try
            Loop
         Catch ex As TwainException
            MessageBox.Show(String.Format("Twain error:{0}Code: {1}{0}Message: {2}", Environment.NewLine, ex.Code, ex.Message))
         Catch ex As Exception
            MessageBox.Show(String.Format("Other error: Message:{0}", ex.Message))
         Finally
            If Not session Is Nothing Then
               session.Shutdown()
            End If
         End Try
      End Sub
using Leadtools;
      using Leadtools.Twain;

      public void _twainSession_AcquirePage(object sender, TwainAcquirePageEventArgs e)
      {
         Application.DoEvents();
         if(e.Image != null)
            e.Image.Dispose();

         e.Cancel = false;
      }
#if !LEADTOOLS_V19_OR_LATER
      public void TwainExceptionExample(IWin32Window parent)
#else
      public void TwainExceptionExample(IntPtr parent)
#endif // #if !LEADTOOLS_V19_OR_LATER
      {
         TwainSession session = null;

         try
         {
            // initialize a new TWAIN session
            session = new TwainSession();
            session.Startup(parent, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None);
            session.AcquirePage += new EventHandler<TwainAcquirePageEventArgs>(_twainSession_AcquirePage);

            // acquire a page, if paper jam, allow the user to retry
            bool done = false;
            while(!done)
            {
               try
               {
                  DialogResult res = session.Acquire(TwainUserInterfaceFlags.Modal | TwainUserInterfaceFlags.Show);
                  MessageBox.Show("Success");
                  done = true;
               }
               catch(TwainException ex)
               {
                  if(ex.Code == TwainExceptionCode.PaperJam)
                  {
                     if(MessageBox.Show("Paper jam.  Fix and retry?", "TWAIN", MessageBoxButtons.YesNo) == DialogResult.No)
                        done = true;
                  }
                  else
                  {
                     // other error, propogate
                     throw ex;
                  }
               }
            }
         }
         catch(TwainException ex)
         {
            MessageBox.Show(string.Format("Twain error:{0}Code: {1}{0}Message: {2}", Environment.NewLine, ex.Code, ex.Message));
         }
         catch(Exception ex)
         {
            MessageBox.Show(string.Format("Other error: Message:{0}", ex.Message));
         }
         finally
         {
            if(session != null)
               session.Shutdown();
         }
      }
必要条件

ターゲットプラットホーム

参照

参照

TwainExceptionメンバ
Leadtools.Twain名前空間