Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Access components on modal form from mainform

Access components on modal form from mainform

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    flyingv
    wrote on last edited by
    #1

    Hello, In my project I have two forms: frmMainForm (Mdi parent) frmLogon (dialog) - components on frmLogon: (edUserName, edPassword, edDatabase) - TextEdit (btnOk, btnCancel) - Buttons In frmMainForm Load event i wrote this code; { frmLogon Logon = new frmLogon(); Logon.ShowDidalog(); if (Logon.DialogResult == DialogResult.OK) { this is my problem, I don't know how can I get values from edUserName, edPassword... to build connectstring. I mean something like that string username = Logon.edUserName.Text; } } I hope you understand me Thank you for answers Anze /*sorry about my bad English*/

    A 1 Reply Last reply
    0
    • F flyingv

      Hello, In my project I have two forms: frmMainForm (Mdi parent) frmLogon (dialog) - components on frmLogon: (edUserName, edPassword, edDatabase) - TextEdit (btnOk, btnCancel) - Buttons In frmMainForm Load event i wrote this code; { frmLogon Logon = new frmLogon(); Logon.ShowDidalog(); if (Logon.DialogResult == DialogResult.OK) { this is my problem, I don't know how can I get values from edUserName, edPassword... to build connectstring. I mean something like that string username = Logon.edUserName.Text; } } I hope you understand me Thank you for answers Anze /*sorry about my bad English*/

      A Offline
      A Offline
      apferreira
      wrote on last edited by
      #2

      The best thing to do is to implement your dialog results through properties of the frmLogon, i.e. In your frmLogon, you begin by declaring some private fields private string userName; private string password; private string databaseName; Then, you create the properties (also in fmrLogon) public string UserName { get { return userName; } set { userName=value } } public string Password { get { return password; } set { password=value } } public string DatabaseName { get { return databaseName; } set { databaseName=value } } After this, don't forget to update your variables when the user presses the OK button. Something like private void button1_Click(object sender, System.EventArgs e) { this.UserName=textBox1.Text; this.Password=textBox2.Text; this.DatabaseName=textBox3.Text; } Having done this, you are now able to access your dialog results in the main form through the properties. For example... frmLogon Logon=new frmLogon; if(Logon.ShowDialog()==DialogResult.Ok) { //Displays the results of the dialog in a textbox in the main form this.myTextBox=Logon.UserName +Logon.Password +Logon.DataBaseName } :)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups