Using VB.Net
I am having the form name as "Employee Entry"
User want to open a Employee Entry from in 5 tabs...
For Example
When the user open a Employee Entry form, while entering the details at that same time, user again open a employee entry form (2nd Employee entry form show like a new employee entry from with out any details)
More Example
We can open Google, Yahoo, in one browser (by using Tab Function).
How to make this.
Need vb.net code Help
I'm assuming this is WinForms? You should design your Employee Entry as a User Control. You can then add a new instance of that control to your Form on each request of a new Employee. You would most likely have a seperate Employee object that you could pass to each instance of your EmployeeEntry user control.
EDIT1
Create a form with a menu strip across the top and a menu item called tsmiNewEmployee. Add a tab control to the form named tabEntryForms and set its fill style to Dock. Delete all default tab pages from it.
Add Class:
public class EmployeeRecord
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime HireDate { get; set; }
}
Add USerControl named EmployeeEntry. Puts osme Firts/Last name edit cotrols on it, etc. Add a Save button and a Cancel Button.
public partial class EmployeeEntry : UserControl
{
public event EventHandler Save;
public event EventHandler Cancel;
private EmployeeRecord empBeingEdited = null;
public EmployeeRecord Employee
{
get
{
return empBeingEdited;
}
set
{
empBeingEdited = value;
if (empBeingEdited == null)
{
// clear controls
}
else
{
// populate controls with employee values
}
}
}
public EmployeeEntry()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
if (Save != null)
Save(this, EventArgs.Empty);
}
private void btnCancel_Click(object sender, EventArgs e)
{
if (Cancel != null)
Cancel(this, EventArgs.Empty);
}
}
And in your main form that has the tab control:
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void tsmiNewEmployee_Click(object sender, EventArgs e)
{
TabPage tab = new TabPage("New Employee Entry");
EmployeeEntry empEntry = new EmployeeEntry();
empEntry.Employee = new EmployeeRecord();
empEntry.Save += new EventHandler(EmployeeEntry_Save);
empEntry.Cancel += new EventHandler(EmployeeEntry_Cancel);
tab.Controls.Add(empEntry);
empEntry.Dock = DockStyle.Fill;
tabEntryForms.TabPages.Add(tab);
}
private void EmployeeEntry_Save(object source, EventArgs args)
{
EmployeeEntry empEntry = source as EmployeeEntry;
MessageBox.Show("Saved");
TabPage parentTab = empEntry.Parent as TabPage;
parentTab.Controls.Remove(empEntry);
tabEntryForms.Controls.Remove(parentTab);
}
private void EmployeeEntry_Cancel(object source, EventArgs args)
{
EmployeeEntry empEntry = source as EmployeeEntry;
MessageBox.Show("NOT Saved");
TabPage parentTab = empEntry.Parent as TabPage;
parentTab.Controls.Remove(empEntry);
tabEntryForms.Controls.Remove(parentTab);
}
}
That should get you started.
Related
I am creating an application on Windows Form and collided with a trouble.
I am getting each second a value from a website by Selenium Webdriver, using XPath and recording it to my local string. I am getting value of a timer. It doesn't matter, it's comfortable to me to get it like a string.
So. I have a loop, which reading data from website and this string I put to TextBox each second too.
But I am not able to see an output of the textBox until my loop is run. I don't want to stop it.
I want to see values from a website online in my application.
Do you have ideas how to refresh the form each second?
I can provide my code if you need.
Thank you in advance, my guru!
public static ChromeDriver GetDriver() {
return new ChromeDriver();
}
public static void CheckGame(string URLevent) {
while (GameIsRun) {
GetInformation(GetDriver(), URLevent);
GameIsRun = false;
}
}
static void GetInformation(ChromeDriver driver, string URLevent) {
driver.Navigate().GoToUrl(URLevent);
do {
TimeOfGame = driver.FindElement(By.XPath("html/body/div/div/div//div/" +
"div[#class='headroom-wrapper']/div//div[3]/div")).GetAttribute("innerHTML");
Print print = new Print()
print.Info(TimeOfGame);
System.Threading.Thread.Sleep(1000);
}
while (TimeOfGame != "90:00");
}
public partial class Form1: Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
Form form = new Form();
}
private static Form1 _form = null;
public static Form1 Form {
get {
if (_form == null) {
_form = new Form1();
}
return _form;
}
}
private void button1_Click(object sender, EventArgs e) {
string eventId = tbEventID.Text; //this works vice versa. It's not my issue.
string URLevent = "url..." + tbEventID.Text + "/";
Program.CheckGame(URLevent);
}
}
public class Print {
public void Info(string TimeOfGame) {
Form1.Form.tbTeam1.Text = TimeOfGame;
//my issue is here. I want to check result at TextBox each second!
}
}
This statement in your code
TimeOfGame = driver.FindElement(By.XPath("html/body/div/div/div//div/div[#class='headroom-wrapper']/div//div[3]/div")).GetAttribute("innerHTML");
is very brittle. You should use getText() method for extracting the inner text of HTML methods. Also, in order to locate webElement precisely, it is preferred to use focused relative Xpath over absolute Xpath.
I have tab pages implementing different views, but I cannot initialize each of the tabs when navigating.
<TabbedPage.Children>
<tabPages:Page1/>
<tabPages:Page2/>
<tabPages:Page3/>
</TabbedPage.Children>
So what I did was to use IActiveAware as prism documentation suggested to know which tab page is currently active. So I have this class:
public abstract class TabbedChildViewModelBase : BaseViewModel, IActiveAware, INavigationAware, IDestructible
protected bool IsInitalized { get; set; }
private bool _IsActive;
public bool IsActive
{
get
{
return _IsActive;
}
set
{
SetProperty(ref _IsActive, value, RaiseIsActiveChanged);
}
}
public event EventHandler IsActiveChanged;
public virtual void OnNavigatingTo(NavigationParameters parameters)
{
}
protected virtual void RaiseIsActiveChanged()
{
IsActiveChanged?.Invoke(this, EventArgs.Empty);
}
public virtual void Destroy()
{
}
}
So each child view models inherits the child view model base:
public class Page1 : TabbedChildViewModelBase
{
public CurrentSeaServiceViewModel()
{
IsActiveChanged += HandleIsActiveTrue;
IsActiveChanged += HandleIsActiveFalse;
}
private void HandleIsActiveTrue(object sender, EventArgs args)
{
if (IsActive == false)
{
TestLabelOnly = "Test";
}
// Handle Logic Here
}
private void HandleIsActiveFalse(object sender, EventArgs args)
{
if (IsActive == true) return;
// Handle Logic Here
}
public override void Destroy()
{
IsActiveChanged -= HandleIsActiveTrue;
IsActiveChanged -= HandleIsActiveFalse;
}
}
The problem is, the child vm isn't initializing. Is there something needed in order to implement IActiveAware properly nor launching the IsActive property
I still used IActiveAware unfortunately, to make the childtabbedviewmodel work you need to bind the page to its own view model.
So here's what I did:
<TabbedPage.Children>
<views:ChildPage1>
<views:ChildPage1.BindingContext>
<viewModels:ChildPage1ViewModel/>
</views:ChildPage1.BindingContext>
</views:ChildPage1>
<views:ChildPage2>
<views:ChildPage2.BindingContext>
<viewModels:ChildPage2ViewModel/>
</views:ChildPage2.BindingContext>
</views:ChildPage2>
</TabbedPage.Children>
I used the property BindingContext of my views and
using IActiveAware I would also know what tab is currently active. Hope anyone helps this who finds trouble binding the child pages of a tab.
How to pass value from one child form to another child form in a mdi parent vb.net
child 1 code -
Dim objKey As New frmKeyboard
objKey.Show()
opens the child 2 form
child 2 code -
Dim Obj As New frmSoll
Obj.strVari = txtSearch.Text
Me.Close()
Try Like This
Form 2 Button_click Event
Dim xfr As New Form3
xfr.MdiParent = Me.MdiParent
xfr.strVari.Text =txtSearch.Text
xfr.Show()
Form3 Button Click
For Each xFrm As Form In CType(Me.MdiParent, Object).MdiChildren
If xFrm.Name = "Form2" Then
CType(xFrm, Object).TextBox2.Text = TextBox1.Text
End If
Next
Me.Close()
Hello another possibility is to use eventhandler and and send messages or values from one child to other via it's parent or even to parent.
Here is my example in c# (sorry I understand VB.NET but don't speak. :) )
Parent form:
/// Mdi parent form
public partial class ParentForm : Form
{
private int ChildCounter = 0;
public ParentForm()
{
InitializeComponent();
this.IsMdiContainer = true;
}
//Child forms will hook to this event handler
public event MessageEventHandler MessageHandler;
/// Sends the message.
public void SendMessage(MessageEventArgs e)
{
if (MessageHandler != null) MessageHandler(e);
}
/// Adds children form.
private void btnAddChildForm_Click(object sender, EventArgs e)
{
var child = new ChildForm(this) { Name = string.Format("child_{0}", ChildCounter++) };
child.Text = child.Name;
child.Show();
}
}
/// Event handler delegate
public delegate void MessageEventHandler(MessageEventArgs e);
/// Message argument with recipient and message
public class MessageEventArgs : EventArgs
{
public string Message { get; set; }
public string Recipient { get; set; }
}
Child form:
/// Children form
public partial class ChildForm : Form
{
//Contructor which will setup child form
public ChildForm(ParentForm parent)
: this()
{
this.MdiParent = parent;
if (parent != null)
parent.MessageHandler += Message_Received; // Register to receive message from handler
}
public ChildForm()
{
InitializeComponent();
}
/// Unregister event receiver while closing form.
protected override void OnClosing(CancelEventArgs e)
{
var parent = this.MdiParent as ParentForm;
if(parent!=null)
{
parent.MessageHandler -= Message_Received;
}
base.OnClosing(e);
}
/// Manage received message.
private void Message_Received(MessageEventArgs e)
{
// When no ricipient all child form will show message.
if (e.Recipient == this.Name || string.IsNullOrEmpty(e.Recipient))
{
txtReceivedMessage.Text = e.Message;
}
this.Refresh();
}
/// Sends message when button pressed.
private void btnSendMessage_Click(object sender, EventArgs e)
{
var parent = MdiParent as ParentForm;
if (this.MdiParent != null)
{
// MessageEventArgs contains information about recipient and message.
parent.SendMessage(new MessageEventArgs() { Recipient = txtRecipientName.Text, Message = txtMessageToSend.Text });
}
}
}
I can't seem to figure out how to display Account ID and Account Balance into a textbox after the selected index is changed in the listbox. I have a Customer class and a Checking account class(which is a subclass of a Bank Account class). The part of the code that is messing up is at the bottom.
This is the part of my code that I'm having trouble with:
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber();
txtBalance.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetBalance().ToString();
This is the rest of the code:
public partial class frmStart : Form
{
private static List<Customer_Account> customers;
private Customer_Account aCustomer;
private Saving_Account aSaver;
private static List<Saving_Account> savers;
private Checking_Account aChecker;
private static List<Checking_Account> checkers;
public frmStart()
{
InitializeComponent();
customers = new List<Customer_Account>();
checkers = new List<Checking_Account>();
savers = new List<Saving_Account>();
}
#region New form for Savings and Checking
private void lstFrmStartChecking_DoubleClick(object sender, EventArgs e)
{
//Shows Checking form
frmChecking showCheckingForm = new frmChecking();
this.Hide();
showCheckingForm.ShowDialog();
this.Close();
}
private void lstFrmStartSavings_SelectedIndexChanged(object sender, EventArgs e)
{
//Show Savings form
frmSavings showSavingForm = new frmSavings();
this.Hide();
showSavingForm.ShowDialog();
this.Close();
}
#endregion
#region Everything needed for TabPage1
//Sets CheckChanged event handler for either New customer or Existing Customer
private void rdoNewCustomer_CheckedChanged(object sender, EventArgs e)
{
groupBox2.Visible = true;
groupBox3.Visible = false;
}
private void rdoExistingCustomer_CheckedChanged(object sender, EventArgs e)
{
groupBox3.Visible = true;
groupBox2.Visible = false;
}//End of CheckChanged event handler
//Button controls for Adding customer to our bank and Clearing the textboxes
//in the 1st group panel
private void btnAddCustomer_Click(object sender, EventArgs e)
{
AddCustomerAccountToList();
PopulateListBox(customers);
}
private void AddCustomerAccountToList()
{
double socialSecurity;
double phoneNumber;
double zipCode;
if (double.TryParse(txtTab1SocialSecurity.Text, out socialSecurity) && double.TryParse(txtTab1PhoneNumber.Text, out phoneNumber)
&& double.TryParse(txtTab1Zip.Text, out zipCode))
{
aCustomer = new Customer_Account(txtTab1SocialSecurity.Text, txtTab1Name.Text, txtTab1Address.Text, txtTab1City.Text,
txtTab1State.Text, txtTab1Zip.Text, txtTab1PhoneNumber.Text, txtTab1Email.Text);
customers.Add(aCustomer);
}
else
{
MessageBox.Show("Please be sure to use only numeric entries for: \nSocial Security \nPhone Number \nZip Code", "Non-numeric Entry");
}
}//End of AddCustomerAccount
private void btnTab1Clear_Click(object sender, EventArgs e)
{
foreach (Control ctrl in groupBox2.Controls)
{
if (ctrl is TextBox)
{
((TextBox)ctrl).Clear();
}
txtTab1SocialSecurity.Focus();
}
}//end of button controls for 1st group panel
//Add CheckingAccount to List()
//Populate ListBox for List<>
private void PopulateListBox(List<Customer_Account> aListCustomerAccount)
{
lstTabPage1.Items.Clear();
lstTabPage2Checking.Items.Clear();
foreach (Customer_Account customer in aListCustomerAccount)
{
lstTabPage1.Items.Add(customer.GetCustomerName().ToUpper());
lstTabPage2Checking.Items.Add(customer.GetCustomerName().ToUpper());
}
}//End of Populate listbox
//Search for an existing member with name
private void txtTabPage1Search_TextChanged(object sender, EventArgs e)
{
for (int i = 0; i < lstTabPage1.Items.Count; i++)
{
if (string.IsNullOrEmpty(txtTabPage1Search.Text))
{
lstTabPage1.SetSelected(i, false);
}
else if (lstTabPage1.GetItemText(lstTabPage1.Items[i]).StartsWith(txtTabPage1Search.Text.ToUpper()))
{
lstTabPage1.SetSelected(i, true);
}
else
{
lstTabPage1.SetSelected(i, false);
}
}
}//End of search
//This button will open a checking account for the customer
private void btnOpenCheckingAccount_Click(object sender, EventArgs e)
{
string acctID;
acctID = txtAccountID.Text;
aChecker = new Checking_Account(acctID, DateTime.Today, 0,
200, frmStart.GetCustomer()[lstTabPage1.SelectedIndex]);
}
//This button will open a saving account for the customer
private void btnOpenSavingsAccount_Click(object sender, EventArgs e)
{
aSaver = new Saving_Account(txtAccountID.Text, DateTime.Today, 0, 0.05,
frmStart.GetCustomer()[lstTabPage1.SelectedIndex]);
}
private static List<Customer_Account> GetCustomer()
{
return customers;
}
#endregion
#region Everything Needed for TabPage2
//Search TabPage 2 Checkers
private void txtTabPage2SearchChecking_TextChanged(object sender, EventArgs e)
{
for (int i = 0; i < lstTabPage2Checking.Items.Count; i++)
{
if (string.IsNullOrEmpty(txtTabPage2SearchChecking.Text))
{
lstTabPage2Checking.SetSelected(i, false);
}
else if (lstTabPage1.GetItemText(lstTabPage2Checking.Items[i]).StartsWith(txtTabPage2SearchChecking.Text.ToUpper()))
{
lstTabPage2Checking.SetSelected(i, true);
}
else
{
lstTabPage2Checking.SetSelected(i, false);
}
}
}//End Search TabPage2 Checkers
//Display values in textboxes depending on user selection in listbox
private void lstTabPage2Checking_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
txtTab2SocialSecurity.Text = customers[lstTabPage2Checking.SelectedIndex].GetSocialSecurity().ToString();
txtTab2Name.Text = customers[lstTabPage2Checking.SelectedIndex].GetCustomerName().ToString();
txtTab2City.Text = customers[lstTabPage2Checking.SelectedIndex].GetCity().ToString();
txtTab2State.Text = customers[lstTabPage2Checking.SelectedIndex].GetState().ToString();
txtTab2Zip.Text = customers[lstTabPage2Checking.SelectedIndex].GetZip().ToString();
txtTab2PhoneNumber.Text = customers[lstTabPage2Checking.SelectedIndex].GetPhoneNumber().ToString();
txtTab2Email.Text = customers[lstTabPage2Checking.SelectedIndex].GetEmail().ToString();
txtTab2Address.Text = customers[lstTabPage2Checking.SelectedIndex].GetAddress().ToString();
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber();
txtBalance.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetBalance().ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
#endregion
}
(This is what the error message says)
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Welcome to SO, Guy!
It looks to me that you are appending the .ToString() method to all of your controls except for this one:
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber();
Change your code to:
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber().ToString();
And you should be fine!
I'm really new at add-in stuff. My code should do these:
An outlook user saves/creates anything. If the created item is an appointment item my system must save it under the c: directory, taking the item subject as file name. Here is my code. What is wrong there?
Note: when I create a new appointment the if clause is working, if I write there any other code, it is working, but I can't get the ai's info, such as ai.Subject.
namespace SendToMRBS
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemLoad += new Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad);
}
void Application_ItemLoad(object Item)
{
if (Item is Outlook.AppointmentItem)
{
Outlook.AppointmentItem ai = Item as Outlook.AppointmentItem;
ai.SaveAs("C:\\" + ai.Subject, Microsoft.Office.Interop.Outlook.OlSaveAsType.olICal);
}
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
I found the solution.. The Item object has no properties or something, so I had to use NewInspector event. Here is my new code:
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemLoad += new Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad);
}
void Application_ItemLoad(object Item)
{
if (Item is Outlook.AppointmentItem)
{
this.Application.Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
}
void Inspectors_NewInspector(Outlook.Inspector Inspector)
{
Outlook.AppointmentItem ai = Inspector.CurrentItem;
ai.Write += new Outlook.ItemEvents_10_WriteEventHandler(ai_Write);
}
void ai_Write(ref bool Cancel)
{
Outlook.Inspector ins = this.Application.ActiveInspector();
Outlook.AppointmentItem appi = ins.CurrentItem;
appi.SaveAs("c:\\test.ics", Microsoft.Office.Interop.Outlook.OlSaveAsType.olICal);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}