Ashwin_shastry
asked on
Opening a windows form from a class library
Hello,
I want to do something very simple here.
I have a class library and in one of the methods I will need to open a new form and wait for user input which basically has just two buttons ( For example YES and NO )
Depending on what the user choses the execution of the program will proceed.
I am doing this right now ..
public void ValidateResultsManually()
{
Form1 form = new Form1();
form.Show();
}
But depending on the user selection my program execution will vary.
So how will I make the execution of the program stop until the user inputs anything... and how would I acess what the user has selected in the form ?
I very new to windows forms and any help would be greatly appreciated.
Thanks,
Ashwin
I want to do something very simple here.
I have a class library and in one of the methods I will need to open a new form and wait for user input which basically has just two buttons ( For example YES and NO )
Depending on what the user choses the execution of the program will proceed.
I am doing this right now ..
public void ValidateResultsManually()
{
Form1 form = new Form1();
form.Show();
}
But depending on the user selection my program execution will vary.
So how will I make the execution of the program stop until the user inputs anything... and how would I acess what the user has selected in the form ?
I very new to windows forms and any help would be greatly appreciated.
Thanks,
Ashwin
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
create a class library, add System.Windows.Forms assembly to it, add a form to it, form code should be like this:
add that ClassLibrary to main project and add code something like this:
using System;
using System.Collections.Generic ;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Form1 form1 = new Form1();
if (form1.ShowDialog() == System.Windows.Forms.Dialo gResult.Ye s)
{
// your code
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication2
{
public partial class Form1 : Form
{
private Button btnNo;
private Button btnYes;
private Label labelMessage;
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.btnNo = new System.Windows.Forms.Button();
this.btnYes = new System.Windows.Forms.Button();
this.labelMessage = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnNo
//
this.btnNo.DialogResult = System.Windows.Forms.DialogResult.No;
this.btnNo.Location = new System.Drawing.Point(205, 92);
this.btnNo.Name = "btnNo";
this.btnNo.Size = new System.Drawing.Size(75, 23);
this.btnNo.TabIndex = 5;
this.btnNo.Text = "No";
this.btnNo.UseVisualStyleBackColor = true;
//
// btnYes
//
this.btnYes.DialogResult = System.Windows.Forms.DialogResult.Yes;
this.btnYes.Location = new System.Drawing.Point(114, 92);
this.btnYes.Name = "btnYes";
this.btnYes.Size = new System.Drawing.Size(75, 23);
this.btnYes.TabIndex = 4;
this.btnYes.Text = "Yes";
this.btnYes.UseVisualStyleBackColor = true;
//
// labelMessage
//
this.labelMessage.AutoSize = true;
this.labelMessage.Location = new System.Drawing.Point(101, 35);
this.labelMessage.Name = "labelMessage";
this.labelMessage.Size = new System.Drawing.Size(132, 13);
this.labelMessage.TabIndex = 3;
this.labelMessage.Text = "Do You want to Continue?";
//
// Form1
//
this.ClientSize = new System.Drawing.Size(392, 142);
this.Controls.Add(this.btnNo);
this.Controls.Add(this.btnYes);
this.Controls.Add(this.labelMessage);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.ResumeLayout(false);
this.PerformLayout();
}
}
}
add that ClassLibrary to main project and add code something like this:
using System;
using System.Collections.Generic
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Form1 form1 = new Form1();
if (form1.ShowDialog() == System.Windows.Forms.Dialo
{
// your code
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
set value like this
form1.TestScenarioName = "First Scenario";
form1.TestScenarioName = "First Scenario";
ASKER
Thanks for quick help guys ...
ASKER
Thanks !
ASKER
Please validate the results for <Test Scenario Name> and mark them as passed or failed.
<Test Scenario Name > will keep changing. How do i set this at run time ?
Thanks,
Ashwin