|
Follow the steps and you will achieve what you want.
1. Declare object of form2 from inside form1.
Form2 f2;
2. In the same manner declare object of form1 from inside form2 (public).
Public Form1 f1;
3. Instantiate form2 from form1 and assign object of form1(f1) to this.
f2 = new Form2();
f2.f1 = this;
f2.show();
Now you have object of form1 in form2.
This way you can pass information of form1 to form2 and by doing reverse you
can pass information of form2 to form1.
Hope this will help!
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
You should never couple a child object to the parent like this when it's possible the child could exist without the parent. Doing so makes the child non reusable. The correct way to do this is for the child to raise events.
Also, you should not expose fields as public. Fields should be private and exposed via a public/internal/protected property as appropriate. This allows for validation and other logic as required later plus the use of locks for multithreading etc...
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Assuming Form1 is the main form that runs when the application starts and is therefore instanciating Form2 ...
Information can be passed from Form2 to Form1 in 3 ways.
1. When you create your Form2 instance, store it in a private field so you can use it outside of the method that does the instanciation. Have an internal or public property that holds the data you need in Form2 . Form1 can access this when required by using the field.Property.
2. The same as 1, but use a method instead of a property.
3. Create a custom EventArgs class, then in Form2 , create an event and a raising method passing an instance of these args. When Form1 creates the Form2 instance, it can subscribe to the event.
1 and 2 require Form1 to poll Form2 for data, in 3 Form2 signals Form1 when there is new data.
Example of 3 - here[^], and further information about events here[^].
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
hi to all,
I am creating an application for authentication Token and my problem is to read the certificate from usb .
Please if Any body is having any idea about it ; reply as early as possible.
Thank you in advance.
|
|
|
|
|
I imagine it would be a lot like reading a certificate from a hard drive.
EDIT: repost.
|
|
|
|
|
Hi all,
I have two forms. On one form is a text box and the other form hold a data table that is the source of a dataset. Upon entering text in the first form and clicking a button, I want to have the text added to the dataset data table. I have unsuccessfully tried instantiating the data table using DataRow newRow...... as the textbox form doesn't allow me to "see" the data table or the dataset. Can someone point me in the right direction here?
Thanks.
|
|
|
|
|
I'm not sure I follow exactly what you are trying to do, but if your data entry form is accessible from the data table form, just make the input text public and read it from the data table form.
If that's not what you need, then perhaps you could explaining your dilemma a little better and let us know what you've tried so far.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Let me simplify things a bit to be more clear. Let's say I have two forms. There is a textbox on Form1 and I'll just have some default text that resides in the textbox. On Form1_Load shown below, frmCalData is instantiated and shown. frmCaldata has a dataset dsCalData with a data table tblCalData.
private void Form1_Load(object sender, EventArgs e)
frmCalData frmCal = new frmCalData();
frmCal.Show();
I believe I should be eventually calling out something like this:
DataRow row = tblCalData.NewRow();
tblCalData.Rows.Add(textbox1.Text);
However, in the Form1_Load method, I cannot call out tblCalData.
As this is new to me, I am shooting somewhat blind, so any guidance will be greatly appreciated.
|
|
|
|
|
When you try to access tblCalData from Form1, what happens? If it gives you an error, what error is shown?
You should be able to access tblCalData from Form1 as frmCal.tblCalData, but it will need to be set public for it to be accessible.
On the other hand, is there a reason that you need both in 2 separate forms?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
DataRow row = frmCal.dataTable1.NewRow (label4.Text,"0","0");
frmCal.dataTable1.Rows.Add(row);
The error is that 'NewRow' Takes '3' arguments. However, there are three columns and the NewRow method indicates that it will create the same schema as the table so I thought I'd have to have place markers for the other two columns.
I have a separate form for just the data table from the main user interface form.
Updated:
Just changed the above to:
DataRow row = frmCal.dataTable1.NewRow();
row[0] = label4.Text;
frmCal.dataTable1.Rows.Add(row);
That works fine. Thanks for keeping me scratching my head
modified on Wednesday, May 5, 2010 10:07 PM
|
|
|
|
|
I know how it goes - sometimes it can be frustrating figuring things out, but it feels so nice when it finally works.
Glad to hear you got it working!
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
|
I have the following class:
class Program
{
static void Main()
{
}
public enum AnimType
{
StickMan
}
public enum StickMan
{
Walk,Run
}
}
This class is used to demo-straight the problem im trying to solve at a simplistic level as otherwise I would have to paste lots of code which is never good.
So that I could use :
Dictionary<(AnimType,STickMan),Animation> animation = new Dictionary<(AnimType,STickMan)();
to get this working:
animation .Add(AnimType.StickMan,StickMan.Walk,new WalkAnimation());
This would allow me to return an Animation object depending on what the animation type (stickman) and the unique animation states (walk,run).
I know that the syntax used for this dictionary is incorrect but its the best way I know how to display it so sorry in advance!
modified on Wednesday, May 5, 2010 2:17 PM
|
|
|
|
|
I would suggest breaking this down a bit more logically... Assuming you plan on adding more animation types, each with its own list of animations, you're going to have a huge collection of enums and no real organization at all... So here's what I would do...
Make a StickMan class, and have it implement a common interface (So you can add more similar classes later)... Let's just call it IAnimationContainer, for example:
public interface IAnimationContainer
{
Animation GetAnimation(string name);
}
public class StickMan : IAnimationContainer
{
private Dictionary<string, Animation> _animations = new Dictionary<string, Animation>();
public StickMan()
{
_animations.Add("Walk", new WalkAnimation());
}
public Animation GetAnimation(string name)
{
return _animations[name];
}
}
Then, you use your dictionary to index AnimTypes to the actual classes...
animations.Add(AnimType.StickMan, new StickMan());
And to get the actual animation:
animations[AnimType.StickMan].GetAnimation("Walk");
|
|
|
|
|
That is brilliant, I have had a hard long day and feel pretty stupid now
...4 Exams in one day !
Thanks !
|
|
|
|
|
can you correct this document the code pls ,thanks
namespace eControlCevertest.lib.Primitives
{/// <summary>
/// la class Gline est un class mere
/// </summary>
public sealed class GLine
{
#region Variables
private bool m_IsDataCorrect;
private LineDefinition m_ContentFormat;
private short
m_CRCComputed = -1,
m_CRCGiven = -1;
private string
m_Code,
m_Value;
#endregion
#region public Accessors
/// <summary>
/// Contient le Code de la donnée etdonne la v aleur, conformement au CDC GiEGLAN
/// </summary>
public string Code
{
get { return m_Code; }
set { m_Code = value; }
}
public LineDefinition ContentFormat
{
get { return m_ContentFormat; }
set { m_ContentFormat = value; }
}
/// <summary>
/// Contient la valeur de la donnée et calcule le ,
/// </summary>
public string Value
{
get { return m_Value; }
set
{
m_Value = value;
ComputeState();
}
}
public short CRCComputed
{
get
{
return m_CRCComputed;
}
}
public short CRCGiven
{
get { return m_CRCGiven; }
set
{
m_CRCGiven = value;
ComputeState();
}
}
public bool IsDataCorrect
{
get
{
return m_CRCGiven != -1 && m_IsDataCorrect;
}
}
/// <summary>
///
/// </summary>
public bool IsDefinitionAvailable
{
get
{
return m_ContentFormat != null;
}
}
#endregion
#region public non default Constructs
/// <summary>
// Constructeurs
/// </summary>
public GLine(string code, string value, short givencrc)
{
m_Code = code;
m_Value = value;
m_CRCGiven = givencrc;
ComputeState();
}
/// <summary>
// Constructeurs .
/// </summary>
public GLine(string code, string value)
{
m_Code = code;
m_Value = value;
m_CRCComputed = Common.CalcCRC(value);
}
/// <summary>
// Constructeurs .
/// </summary>
public GLine(string code, LineDefinition definition)
{
m_Code = code;
m_ContentFormat = definition;
}
#endregion
/// <summary>
/// fonction pour Calculer les valeurs.
/// </summary>
private void ComputeState()
{
m_CRCComputed = Common.CalcCRC(m_Value);
m_IsDataCorrect = m_CRCGiven == m_CRCComputed;
}
}
}
|
|
|
|
|
What do you mean? Edit your question to make it descriptive and post only the relevant code within "pre" tags.
|
|
|
|
|
toto_2010 wrote: can you correct this document the code pls ,thanks
I appreciate that English is probably not your first language, but can you try rewording this to make a clearer question?
It's time for a new signature.
|
|
|
|
|
toto_2010 wrote: can you correct this document the code pls
Without us knowing what you are trying to achieve here, and what the problem you are having is, then no. I will tell you though that you have a potential issue in your code when you set a property and then call ComputeState. What happens if you don't actually change the value, but reassign one that's already there?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Noone is going to fix your code or write your documentation for you. We can point you in the right direction, but you have to ask a question we can understand first.
|
|
|
|
|
I do not find type "LineDefinition" anywhere.
I derived following code from your distorted code.
public sealed class GLine
{
#region Variables
private bool m_IsDataCorrect;
private LineDefinition m_ContentFormat;
private short m_CRCComputed = -1, m_CRCGiven = -1;
private string m_Code, m_Value;
#endregion
#region public Accessors
public string Code
{
get { return m_Code; }
set { m_Code = value; }
}
public LineDefinition ContentFormat
{
get { return m_ContentFormat; }
set { m_ContentFormat = value; }
}
public string Value
{
get { return m_Value; }
set
{
m_Value = value;
ComputeState();
}
}
public short CRCComputed
{
get
{
return m_CRCComputed;
}
}
public short CRCGiven
{
get { return m_CRCGiven; }
set
{
m_CRCGiven = value;
ComputeState();
}
}
public bool IsDataCorrect
{
get
{
return m_CRCGiven != -1 && m_IsDataCorrect;
}
}
public bool IsDefinitionAvailable
{
get
{
return m_ContentFormat != null;
}
}
#endregion
#region public non default Constructs
public GLine(string code, string value, short givencrc)
{
m_Code = code;
m_Value = value;
m_CRCGiven = givencrc;
ComputeState();
}
public GLine(string code, string value)
{
m_Code = code;
m_Value = value;
m_CRCComputed = Common.CalcCRC(value);
}
public GLine(string code, LineDefinition definition)
{
m_Code = code;
m_ContentFormat = definition;
}
#endregion
private void ComputeState()
{
m_CRCComputed = Common.CalcCRC(m_Value);
m_IsDataCorrect = m_CRCGiven == m_CRCComputed;
}
}
So unable to find what is exact problem with
this code...
Hope this will help!
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Hi all,
I am facing problem in displaying the Date formate in Excel .
From Database i am displaying the Date lets say the Formate "dd/mm/yy" e.g 03/05/10. nothing but (3rd May 2010)
The above formate is displaying in correctly in English settings but when the client generating the excel, there it is displaying as "05/03/10" i mean day and month are interchanging.
(Because they are using Italian settings due to this reason date is displaying like 05/03/10)
Can any body help on this?Date formate should not interchange
Thanks in advance,
Balu.
|
|
|
|
|
|
|
I would leave it as is.
They have Italian settings for a reason (are they Italian perhaps) so they will want dates to show in the Italian format.
The only time I think it is legitimate to force a date format is with regard to American settings when coding for British users. Unfortunately Microsoft in their wisdom default English settings to be American English, even on editions of software produced specifically for the British market. Consequently many British people have American settings by mistake. This is especially a problem with SQL Server, which will not install in British English no matter how hard you try (causing no end of trouble with reporting services), and must be changed afterwards. In fact only the execution language can be changed, the root installed language settings cannot be changed! All other culture settings should be respected.
|
|
|
|