View on GitHub

SARAFF SOFTWARE

All products / Saraff.Twain.NET / Contents

Minimal implementation

For this it suffices invoke the method Acquire and handle an event AcquireCompleted.

partial class Form1 {

    public Form1() {
        InitializeComponent();
    }

    private void button1_Click(object sender,EventArgs e) {
        try {
            this._twain.Acquire();
        } catch(Exception ex) {
            MessageBox.Show(ex.Message,"SAMPLE1",MessageBoxButtons.OK,MessageBoxIcon.Error);
        }
    }

    private void _twain_AcquireCompleted(object sender,EventArgs e) {
        try {
            if(this.pictureBox1.Image!=null) {
                this.pictureBox1.Image.Dispose();
            }
            if(this._twain.ImageCount>0) {
                this.pictureBox1.Image=this._twain.GetImage(0);
            }
        } catch(Exception ex) {
            MessageBox.Show(ex.Message,"SAMPLE1",MessageBoxButtons.OK,MessageBoxIcon.Error);
        }
    }
}

To select a DS, you must invoke SelectSource.

partial class Form1 {

    public Form1() {
        InitializeComponent();
        try {
            this._twain.OpenDSM();
        } catch(Exception ex) {
            MessageBox.Show(ex.Message,"SAMPLE1",MessageBoxButtons.OK,MessageBoxIcon.Error);
        }

    }

    private void button2_Click(object sender,EventArgs e) {
        try {
            this._twain.CloseDataSource();
            this._twain.SelectSource();
        } catch(Exception ex) {
            MessageBox.Show(ex.Message,"SAMPLE1",MessageBoxButtons.OK,MessageBoxIcon.Error);
        }
    }

    private void button1_Click(object sender,EventArgs e) {
        try {
            this._twain.Acquire();
        } catch(TwainException ex) {
            MessageBox.Show(ex.Message,"SAMPLE1",MessageBoxButtons.OK,MessageBoxIcon.Error);
        }
    }

    private void _twain_AcquireCompleted(object sender,EventArgs e) {
        try {
            if(this.pictureBox1.Image!=null) {
                this.pictureBox1.Image.Dispose();
            }
            if(this._twain.ImageCount>0) {
                this.pictureBox1.Image=this._twain.GetImage(0);
            }
        } catch(Exception ex) {
            MessageBox.Show(ex.Message,"SAMPLE1",MessageBoxButtons.OK,MessageBoxIcon.Error);
        }
    }
}