mirror of
https://github.com/soukoku/ntwain.git
synced 2025-12-20 03:59:56 +08:00
Added open/close to test form.
This commit is contained in:
105
samples/WinForm32/Form1.Designer.cs
generated
105
samples/WinForm32/Form1.Designer.cs
generated
@@ -35,11 +35,19 @@
|
|||||||
lblCurrent = new System.Windows.Forms.Label();
|
lblCurrent = new System.Windows.Forms.Label();
|
||||||
btnEnumSources = new System.Windows.Forms.Button();
|
btnEnumSources = new System.Windows.Forms.Button();
|
||||||
listSources = new System.Windows.Forms.ListBox();
|
listSources = new System.Windows.Forms.ListBox();
|
||||||
|
btnSetDef = new System.Windows.Forms.Button();
|
||||||
|
btnOpen = new System.Windows.Forms.Button();
|
||||||
|
splitContainer1 = new System.Windows.Forms.SplitContainer();
|
||||||
|
btnClose = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
|
||||||
|
splitContainer1.Panel1.SuspendLayout();
|
||||||
|
splitContainer1.Panel2.SuspendLayout();
|
||||||
|
splitContainer1.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// btnSelect
|
// btnSelect
|
||||||
//
|
//
|
||||||
btnSelect.Location = new System.Drawing.Point(12, 12);
|
btnSelect.Location = new System.Drawing.Point(13, 14);
|
||||||
btnSelect.Name = "btnSelect";
|
btnSelect.Name = "btnSelect";
|
||||||
btnSelect.Size = new System.Drawing.Size(151, 23);
|
btnSelect.Size = new System.Drawing.Size(151, 23);
|
||||||
btnSelect.TabIndex = 0;
|
btnSelect.TabIndex = 0;
|
||||||
@@ -50,7 +58,7 @@
|
|||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
label1.AutoSize = true;
|
label1.AutoSize = true;
|
||||||
label1.Location = new System.Drawing.Point(12, 51);
|
label1.Location = new System.Drawing.Point(13, 53);
|
||||||
label1.Name = "label1";
|
label1.Name = "label1";
|
||||||
label1.Size = new System.Drawing.Size(98, 15);
|
label1.Size = new System.Drawing.Size(98, 15);
|
||||||
label1.TabIndex = 1;
|
label1.TabIndex = 1;
|
||||||
@@ -59,7 +67,7 @@
|
|||||||
// lblDefault
|
// lblDefault
|
||||||
//
|
//
|
||||||
lblDefault.AutoSize = true;
|
lblDefault.AutoSize = true;
|
||||||
lblDefault.Location = new System.Drawing.Point(115, 51);
|
lblDefault.Location = new System.Drawing.Point(116, 53);
|
||||||
lblDefault.Name = "lblDefault";
|
lblDefault.Name = "lblDefault";
|
||||||
lblDefault.Size = new System.Drawing.Size(24, 15);
|
lblDefault.Size = new System.Drawing.Size(24, 15);
|
||||||
lblDefault.TabIndex = 2;
|
lblDefault.TabIndex = 2;
|
||||||
@@ -68,7 +76,7 @@
|
|||||||
// label2
|
// label2
|
||||||
//
|
//
|
||||||
label2.AutoSize = true;
|
label2.AutoSize = true;
|
||||||
label2.Location = new System.Drawing.Point(12, 81);
|
label2.Location = new System.Drawing.Point(13, 14);
|
||||||
label2.Name = "label2";
|
label2.Name = "label2";
|
||||||
label2.Size = new System.Drawing.Size(97, 15);
|
label2.Size = new System.Drawing.Size(97, 15);
|
||||||
label2.TabIndex = 3;
|
label2.TabIndex = 3;
|
||||||
@@ -77,7 +85,7 @@
|
|||||||
// lblCurrent
|
// lblCurrent
|
||||||
//
|
//
|
||||||
lblCurrent.AutoSize = true;
|
lblCurrent.AutoSize = true;
|
||||||
lblCurrent.Location = new System.Drawing.Point(115, 81);
|
lblCurrent.Location = new System.Drawing.Point(116, 14);
|
||||||
lblCurrent.Name = "lblCurrent";
|
lblCurrent.Name = "lblCurrent";
|
||||||
lblCurrent.Size = new System.Drawing.Size(24, 15);
|
lblCurrent.Size = new System.Drawing.Size(24, 15);
|
||||||
lblCurrent.TabIndex = 4;
|
lblCurrent.TabIndex = 4;
|
||||||
@@ -85,7 +93,7 @@
|
|||||||
//
|
//
|
||||||
// btnEnumSources
|
// btnEnumSources
|
||||||
//
|
//
|
||||||
btnEnumSources.Location = new System.Drawing.Point(12, 114);
|
btnEnumSources.Location = new System.Drawing.Point(13, 81);
|
||||||
btnEnumSources.Name = "btnEnumSources";
|
btnEnumSources.Name = "btnEnumSources";
|
||||||
btnEnumSources.Size = new System.Drawing.Size(151, 23);
|
btnEnumSources.Size = new System.Drawing.Size(151, 23);
|
||||||
btnEnumSources.TabIndex = 5;
|
btnEnumSources.TabIndex = 5;
|
||||||
@@ -95,30 +103,87 @@
|
|||||||
//
|
//
|
||||||
// listSources
|
// listSources
|
||||||
//
|
//
|
||||||
listSources.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
|
listSources.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
|
||||||
listSources.FormattingEnabled = true;
|
listSources.FormattingEnabled = true;
|
||||||
listSources.ItemHeight = 15;
|
listSources.ItemHeight = 15;
|
||||||
listSources.Location = new System.Drawing.Point(12, 143);
|
listSources.Location = new System.Drawing.Point(13, 115);
|
||||||
listSources.Name = "listSources";
|
listSources.Name = "listSources";
|
||||||
listSources.Size = new System.Drawing.Size(279, 289);
|
listSources.Size = new System.Drawing.Size(289, 394);
|
||||||
listSources.TabIndex = 6;
|
listSources.TabIndex = 6;
|
||||||
//
|
//
|
||||||
|
// btnSetDef
|
||||||
|
//
|
||||||
|
btnSetDef.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
|
||||||
|
btnSetDef.Location = new System.Drawing.Point(12, 515);
|
||||||
|
btnSetDef.Name = "btnSetDef";
|
||||||
|
btnSetDef.Size = new System.Drawing.Size(169, 23);
|
||||||
|
btnSetDef.TabIndex = 7;
|
||||||
|
btnSetDef.Text = "Set selected as default";
|
||||||
|
btnSetDef.UseVisualStyleBackColor = true;
|
||||||
|
btnSetDef.Click += btnSetDef_Click;
|
||||||
|
//
|
||||||
|
// btnOpen
|
||||||
|
//
|
||||||
|
btnOpen.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;
|
||||||
|
btnOpen.Location = new System.Drawing.Point(187, 515);
|
||||||
|
btnOpen.Name = "btnOpen";
|
||||||
|
btnOpen.Size = new System.Drawing.Size(104, 23);
|
||||||
|
btnOpen.TabIndex = 8;
|
||||||
|
btnOpen.Text = "Open selected";
|
||||||
|
btnOpen.UseVisualStyleBackColor = true;
|
||||||
|
btnOpen.Click += btnOpen_Click;
|
||||||
|
//
|
||||||
|
// splitContainer1
|
||||||
|
//
|
||||||
|
splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
|
||||||
|
splitContainer1.Location = new System.Drawing.Point(0, 0);
|
||||||
|
splitContainer1.Name = "splitContainer1";
|
||||||
|
//
|
||||||
|
// splitContainer1.Panel1
|
||||||
|
//
|
||||||
|
splitContainer1.Panel1.Controls.Add(btnSelect);
|
||||||
|
splitContainer1.Panel1.Controls.Add(btnOpen);
|
||||||
|
splitContainer1.Panel1.Controls.Add(label1);
|
||||||
|
splitContainer1.Panel1.Controls.Add(btnSetDef);
|
||||||
|
splitContainer1.Panel1.Controls.Add(lblDefault);
|
||||||
|
splitContainer1.Panel1.Controls.Add(listSources);
|
||||||
|
splitContainer1.Panel1.Controls.Add(btnEnumSources);
|
||||||
|
//
|
||||||
|
// splitContainer1.Panel2
|
||||||
|
//
|
||||||
|
splitContainer1.Panel2.Controls.Add(btnClose);
|
||||||
|
splitContainer1.Panel2.Controls.Add(label2);
|
||||||
|
splitContainer1.Panel2.Controls.Add(lblCurrent);
|
||||||
|
splitContainer1.Size = new System.Drawing.Size(800, 564);
|
||||||
|
splitContainer1.SplitterDistance = 305;
|
||||||
|
splitContainer1.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// btnClose
|
||||||
|
//
|
||||||
|
btnClose.Location = new System.Drawing.Point(13, 45);
|
||||||
|
btnClose.Name = "btnClose";
|
||||||
|
btnClose.Size = new System.Drawing.Size(142, 23);
|
||||||
|
btnClose.TabIndex = 0;
|
||||||
|
btnClose.Text = "Close current source";
|
||||||
|
btnClose.UseVisualStyleBackColor = true;
|
||||||
|
btnClose.Click += btnClose_Click;
|
||||||
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
ClientSize = new System.Drawing.Size(800, 450);
|
ClientSize = new System.Drawing.Size(800, 564);
|
||||||
Controls.Add(listSources);
|
Controls.Add(splitContainer1);
|
||||||
Controls.Add(btnEnumSources);
|
|
||||||
Controls.Add(lblCurrent);
|
|
||||||
Controls.Add(label2);
|
|
||||||
Controls.Add(lblDefault);
|
|
||||||
Controls.Add(label1);
|
|
||||||
Controls.Add(btnSelect);
|
|
||||||
Name = "Form1";
|
Name = "Form1";
|
||||||
Text = "TWAIN Test";
|
Text = "TWAIN Test";
|
||||||
|
splitContainer1.Panel1.ResumeLayout(false);
|
||||||
|
splitContainer1.Panel1.PerformLayout();
|
||||||
|
splitContainer1.Panel2.ResumeLayout(false);
|
||||||
|
splitContainer1.Panel2.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit();
|
||||||
|
splitContainer1.ResumeLayout(false);
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -130,5 +195,9 @@
|
|||||||
private System.Windows.Forms.Label lblCurrent;
|
private System.Windows.Forms.Label lblCurrent;
|
||||||
private System.Windows.Forms.Button btnEnumSources;
|
private System.Windows.Forms.Button btnEnumSources;
|
||||||
private System.Windows.Forms.ListBox listSources;
|
private System.Windows.Forms.ListBox listSources;
|
||||||
|
private System.Windows.Forms.Button btnSetDef;
|
||||||
|
private System.Windows.Forms.Button btnOpen;
|
||||||
|
private System.Windows.Forms.SplitContainer splitContainer1;
|
||||||
|
private System.Windows.Forms.Button btnClose;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ namespace WinForm32
|
|||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
Text += TwainPlatform.Is32bit ? " 32bit" : " 64bit";
|
||||||
TwainPlatform.PreferLegacyDSM = true;
|
TwainPlatform.PreferLegacyDSM = true;
|
||||||
|
|
||||||
twain = new TwainSession(Assembly.GetExecutingAssembly().Location);
|
twain = new TwainSession(Assembly.GetExecutingAssembly().Location);
|
||||||
@@ -70,5 +70,26 @@ namespace WinForm32
|
|||||||
listSources.Items.Add(ds);
|
listSources.Items.Add(ds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btnSetDef_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listSources.SelectedItem is TW_IDENTITY_LEGACY ds)
|
||||||
|
{
|
||||||
|
twain.DGControl.Identity.Set(ds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnOpen_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listSources.SelectedItem is TW_IDENTITY_LEGACY ds)
|
||||||
|
{
|
||||||
|
twain.DGControl.Identity.OpenDS(ds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnClose_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
twain.DGControl.Identity.CloseDS();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,10 +92,21 @@ namespace NTwain
|
|||||||
/// <returns>The final state.</returns>
|
/// <returns>The final state.</returns>
|
||||||
public STATE TryStepdown(STATE targetState)
|
public STATE TryStepdown(STATE targetState)
|
||||||
{
|
{
|
||||||
if (State > targetState)
|
int tries = 0;
|
||||||
|
while (State > targetState)
|
||||||
{
|
{
|
||||||
// shouldn't care about handle when closing really
|
if (tries++ > 5) break;
|
||||||
DGControl.Parent.CloseDSM(ref _hwnd);
|
|
||||||
|
switch (State)
|
||||||
|
{
|
||||||
|
case STATE.S4:
|
||||||
|
DGControl.Identity.CloseDS();
|
||||||
|
break;
|
||||||
|
case STATE.S3:
|
||||||
|
// shouldn't care about handle when closing really
|
||||||
|
DGControl.Parent.CloseDSM(ref _hwnd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return State;
|
return State;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user