|
Firstly, don't use Dispose, use Close instead - it will be disposed later when the CG gets round to it. Remember that your form may have results that the main form expects to be able to pick up.
Instead, either
1) Pass the frmStart instance to frmReader (not brilliant, but it will work) and use the Show method on it before you Close() frmReader. This may give you problems if you miss a way to close teh form that you are not handling.
or
2) Use R1.ShowDialog(); instead of R1.Show(); This will prevent frmStart from proceeding until frmReader is closed. It can then unhide itself. (Much preferable, as frmReader can be more generic and does not need to know about the existance of frmStart)
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OriginalGriff wrote: it will be disposed later when the CG gets round to it.
Nah. I don't expect Christian flies around the world collecting our junk.
|
|
|
|
|
Good spot!
|
|
|
|
|
Luc Pattyn wrote: I don't expect Christian flies around the world collecting our junk.
He can't - all airlines suck today
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Handle the FormClosing event of R1 in frmstart and it can unhide itself.
using System;
using System.Windows.Forms;
public partial class FormStart : Form
{
public FormStart()
{
InitializeComponent();
Click += new EventHandler(FormStart_Click);
}
private void FormStart_Click(object sender, EventArgs e)
{
ShowFormReader();
}
private void ShowFormReader()
{
FormReader formReader = new FormReader();
formReader.FormClosing += new FormClosingEventHandler(formReader_FormClosing);
formReader.Show();
Hide();
}
private void formReader_FormClosing(object sender, FormClosingEventArgs e)
{
Show();
}
}
If it's not a close of R1 that triggers this then you can easily create a custom event and handle that.
|
|
|
|
|
WRT your code, I want to get data from FormReader to FormStart.
I uses following 2 approaches:
A)
FormReader formReader = new FormReader(this);
Now, making FormStart member as internal/public accessing them on FormReader.
B)On click(here its closing) event handler as you did
private void formReader_FormClosing(object sender, FormClosingEventArgs e)
{
}
But here i have to make FormReader Member internal/public
My question is,
Which approach is good?
As in first we are making parent form member public,
But,In 2nd we are child form member public.
Or is there any other way?
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Also If i have a case like
interface IA
{
void M();
}
interface IB
{
void M();
}
class ABC : IA, IB
{
public void M()
{
MessageBox.Show("Hello");
}
}
ABC a = new ABC();
a.M();
Whose Interface method i am implementing?
Its running not giving error?
What is the use of this definition ?
And what should i do if i want to implement IA not IB or vice versa.
Or by default its calling/implementing IA M, as it's mentioned 1st as ABC:IA,IB
|
|
|
|
|
With regard to your first question - getting data from FormReader to FormStart :
Do NOT use method A. It works but it is a nasty hack that as things get more complex you will regret!
Method B does not require any change to the access modifier of FormReader . The sender parameter will (normally) be the FormReader instance. So, inside the handler add something like this:
FormReader formReader = sender as FormReader;
if(formReader != null)
{
}
There is another method if you want FormReader to inform FormStart that there is data it may be interested in - you can raise a custom event in FormReader and subscribe to that in FormStart . Have a look at this tip[^], this tip[^], then this article[^] if this would fit your case better.
|
|
|
|
|
Sorry, forgot your second question!
The answer is neither. An interface has no implementation so you never actually use any methods/properties/events they appear to have. You always use the implementation in the class that provides the implementation.
|
|
|
|
|
Dave's approach is fine.
Maybe a simpler approach is also acceptable: if the one form is hidden while the other is shown, the latter probably could be shown as a dialog, hence:
this.Hide();
otherForm.ShowDialog();
this.Show();
|
|
|
|
|
I finally made it working!!! I made a test here actually and i made it work. I can save and load from a text file...yeeey.
How can I made it more compact? I want to transform it into a stand alone Class that I can call it from anywhere in any situation. Any suggestions?
Thanks
Here is the 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;
using SaveLoadNamespace;
using WarningsNamespace;
using System.Text.RegularExpressions;
namespace test7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SaveLoadClass slc = new SaveLoadClass();
WarningsClass wc = new WarningsClass();
string tampon;
private void buttonSave_Click(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
tampon = "checkBox = true" + "\r\n";
}
else
{
tampon = "checkBox = false" + "\r\n";
}
tampon += "numericUpDown = " + numericUpDown1.Value.ToString() + "\r\n"; ;
tampon += "comboBox = " + comboBox1.Text + "\r\n"; ;
slc.file_SaveFile(tampon); label2.Text = wc.w2;
}
string buffer, s = ""; int i, j = 0;
private void buttonLoad_Click(object sender, EventArgs e)
{
slc.file_LoadFile(); label1.Text = buffer = slc.textToLoadInto; label3.Text = wc.w5;
#region <_____ NumericUpDown _____>
if (buffer.Contains("numericUpDown"))
{
i = buffer.IndexOf("numericUpDown");
s = buffer.Remove(0, i);
if (s.Contains("\r\n"))
{
i = s.IndexOf("\r\n");
j = s.Length - i;
s = s.Remove(i, j);
}
if (s.Contains("="))
{
i = s.IndexOf("=") + 1;
s = s.Remove(0, i).Trim();
}
i = int.Parse(s);
numericUpDown1.Value = i;
}
#endregion >NumericUpDown-END<
#region <_____ checkBox _____>
if (buffer.Contains("checkBox"))
{
i = buffer.IndexOf("checkBox");
s = buffer.Remove(0, i);
if (s.Contains("\r\n"))
{
i = s.IndexOf("\r\n");
j = s.Length - i;
s = s.Remove(i, j);
}
if (s.Contains("="))
{
i = s.IndexOf("=") + 1;
s = s.Remove(0, i).Trim();
}
if (s.Contains("true"))
{
checkBox1.Checked = true;
}
if (s.Contains("false"))
{
checkBox1.Checked = false;
}
}
#endregion >checkBox-END<
#region <_____ comboBox _____>
if (buffer.Contains("comboBox"))
{
i = buffer.IndexOf("comboBox");
s = buffer.Remove(0, i);
if (s.Contains("\r\n"))
{
i = s.IndexOf("\r\n");
j = s.Length - i;
s = s.Remove(i, j);
}
if (s.Contains("="))
{
i = s.IndexOf("=") + 1;
s = s.Remove(0, i).Trim();
}
comboBox1.Text = s;
}
#endregion >comboBox-END<
}
}
}
The output is like this:
checkBox = true
numericUpDown = 24
comboBox = red
|
|
|
|
|
Hi,
you could build a method to which you can pass a form. To get the controls at the passed form use the Controls-Property:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controls.aspx[^]
Check the type of each control to get the name like 'checkBox' for your string.
Btw: Instead of using the type-name of each control I would suggest using the ID, so that you can store more than one checkbox for example.
Hope this helps you a bit.
Regards
Sebastian
|
|
|
|
|
Its a good suggestion and i understand it because i see it some time ago used by others ... But, its too advanced for me for the moment and I wish to make it in some limited way that i can understand what i write there... But,I will look into it and I will strive to understand it how its done and try to use it...but small chance for me to accomplish that kind of maneuverability.
Thanks
|
|
|
|
|
My idea is to make some overloads methods for: [int,string,bool](i suppose even for a object but is a to high standard for me). What do you think?
|
|
|
|
|
What possessed you to declare a local variable called tampon ?
/ravi
|
|
|
|
|
I was actually thinking on "TRAIN Buffer" ,but in my language "tampon" actually is the word for "TRAIN Buffer"or 1.damper,2. bumper,3. fender, 4. shock, 5. buffer. I was not thinking at all at other meanings other than what i described ... sorry if i mislead you. I will change his name soon.
|
|
|
|
|
That's OK - it just made me laugh.
/ravi
|
|
|
|
|
Congratulations on getting your code to work This approach isnt very dynamic tho and if you add or remove fields you would have to modify your save/load methods. I suggest that you read some articles about Serialization. Start with XML serialization, that way you can open the xml file in your browser and see everything. binary serialization isnt very fun to look at :].
A FOO walked into a BAR, and the horse said..
|
|
|
|
|
I think I made it how I like it the most and i can proudly name it that is all right ... 2 nights over this but I bring it down right where I want it to be. Phew.
Now I am happy with it.
I know i must learn and assimilate /the faster the better/ the arrays and lists that you all master them soooo well, and i am angry for that, but... i will.
About this matter, some good exercises that cant be done without them(arrays&lists&othersLikeThem) ,and who can be done without make me thinking about what I know already but direct me to learn them well? Thanks,and I appreciate.
So, here is my Class:
using System.Windows.Forms;
using SaveLoadNamespace;
namespace ExtractionsNamespace
{
public class ExtractionsClass
{
SaveLoadClass slc = new SaveLoadClass();
public string tampon;
#region <_____ AddControl _____>
#endregion >AddControl-END<
public void AddControl(Control c, bool checkToAdd)
{
if (checkToAdd)
tampon += c.Name + " = true" + "\r\n";
else tampon += c.Name + " = false" + "\r\n";
}
public void AddControl(Control c, string textToAdd)
{
tampon += c.Name + " = " + textToAdd + " \r\n";
}
public void AddControl(Control c, int valueToAdd)
{
tampon += c.Name + " = " + valueToAdd + " \r\n";
}
public void EraseAll()
{
tampon = "";
}
public string buffer; string s = ""; int i, j = 0; bool tf;
private void Extracttor(string _TextToExtract_)
{
i = buffer.IndexOf(_TextToExtract_);
s = buffer.Remove(0, i);
if (s.Contains("\r\n"))
{
i = s.IndexOf("\r\n");
j = s.Length - i;
s = s.Remove(i, j);
}
if (s.Contains("="))
{
i = s.IndexOf("=") + 1;
s = s.Remove(0, i).Trim();
}
}
public int Extract_int(string _TextToSearchFor_)
{
if (buffer.Contains(_TextToSearchFor_))
{
Extracttor(_TextToSearchFor_);
i = int.Parse(s);
}
return i;
}
public bool Extract_bool(string _TextToSearchFor_)
{
if (buffer.Contains(_TextToSearchFor_))
{
Extracttor(_TextToSearchFor_);
}
if (s.Contains("true"))
{
tf = true;
}
if (s.Contains("false"))
{
tf = false;
}
return tf;
}
public string Extract_string(string _TextToSearchFor_)
{
if (buffer.Contains(_TextToSearchFor_))
{
Extracttor(_TextToSearchFor_);
return s;
}
return "string_?";
}
public void file_SaveFileX()
{
slc.file_SaveFile(tampon);
}
public string file_LoadFileX()
{
slc.file_LoadFile();
return buffer = slc.textToLoadInto;
}
}
}
And here is the implementation on form:
using System;
using System.Windows.Forms;
using WarningsNamespace;
using ExtractionsNamespace;
namespace test7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
WarningsClass wc = new WarningsClass();
ExtractionsClass ex = new ExtractionsClass();
private void buttonSave_Click(object sender, EventArgs e)
{
ex.EraseAll();
ex.AddControl(checkBox1, checkBox1.Checked);
ex.AddControl(checkBox2, checkBox2.Checked);
ex.AddControl(checkBox3, checkBox3.Checked);
ex.AddControl(numericUpDown1, numericUpDown1.Value.ToString());
ex.AddControl(numericUpDown2, numericUpDown2.Value.ToString());
ex.AddControl(comboBox1, comboBox1.Text);
ex.AddControl(progressBar1, progressBar1.Value);
ex.AddControl(radioButton1, radioButton1.Checked);
ex.AddControl(radioButton2, radioButton2.Checked);
ex.AddControl(radioButton3, radioButton3.Checked);
ex.file_SaveFileX(); label2.Text = wc.w2;
}
private void buttonLoad_Click(object sender, EventArgs e)
{
label1.Text = ex.file_LoadFileX(); label3.Text = wc.w5;
checkBox1.Checked = ex.Extract_bool("checkBox1");
checkBox2.Checked = ex.Extract_bool("checkBox2");
checkBox3.Checked = ex.Extract_bool("checkBox3");
numericUpDown1.Value = ex.Extract_int("numericUpDown1");
numericUpDown2.Value = ex.Extract_int("numericUpDown2");
comboBox1.Text = ex.Extract_string("comboBox1");
progressBar1.Value = ex.Extract_int("progressBar1");
radioButton1.Checked = ex.Extract_bool("radioButton1");
radioButton2.Checked = ex.Extract_bool("radioButton2");
radioButton3.Checked = ex.Extract_bool("radioButton3");
}
#region <_____ mouseProgressBar _____>
int somemousecoordonates;
private void progressBar1_MouseMove(object sender, MouseEventArgs e)
{
somemousecoordonates = e.X;
}
private void progressBar1_Click(object sender, EventArgs e)
{
progressBar1.Value = somemousecoordonates;
label2.Text = somemousecoordonates.ToString();
}
#endregion >mouseProgressBar-END<
BTW, this is what i call a perfect example of [Code Library]. Something like this somewhere, cant be found? Of course for other subjects and matters(not just for savings or loadings).
And the Output is looking like this somewhere in a text file:
checkBox1 = true
checkBox2 = false
checkBox3 = true
numericUpDown1 = 14
numericUpDown2 = 56
comboBox1 = red
progressBar1 = 5
radioButton1 = false
radioButton2 = true
radioButton3 = false
Thanks for all the support.
|
|
|
|
|
I need a suggestion from you:
I want to make a saving program that is for windows only (not for internet) and who can imitate the Forum(in general) type of writing a text , store and display. Like the one i am writing right now. With a list box to display some saved text from a file, a textbox under -to write and save into that file.And a comboBox that can sort all "posts". Basically this is the hard part, the rest are decorations.
How do you recommend me to do:
Make for every "post" a file (for 100 posts will be 100 files) and the sorting is based on those files-its more intuitive to program it this way for me in my stage.
OR - the very hard part: (because i know only the basics in string manipulation)...
Make a single file with all the text and sorted it out by manipulating a string who contain the entire file.(a string that can retain in itself 99999999999999 characters-its even possible?-i doubt it.
OR
Again a single file that can be sorted but with the help of another one that contain some [sortings by address] from that large one. Basically there will be 2 files one with keywords representing addresses and the text attached to them, and the second one with only the keywords address.
But This is a little overwhelming for me to think about and i seek help from you, the guru of programming world.
Please give me a good solution...and how to think it through(programmatically).
Thank you.
|
|
|
|
|
Hi,Frinds.
I have a code that install sql server 2005 through code with command line argument written in bat file.
It was working fine on my machine with out any problem.
But on other machine its not. its terminating with out giving any kind of error . the machine i am tring allready have .net framework, win installer 3.1 and crystal report framework. Can u please tell me the problem. Thank you
|
|
|
|
|
I'm using BO XI R2.
I want to modify the report.
Following is a code snippet which throws InvalidCastException;
and under that the Message is No Such Interfaces Supported.
Kindly suggest me a solution, if you have been able to crack it.
Also any ideas why such an exception.
using CrystalDecisions.CrystalReports.TemplateEngine;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.ObjectFactory;
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.CommonObjectModel;
using CrystalDecisions.ReportAppServer.ReportDefModel;
ReportClientDocument reportClientDocument = new ReportClientDocument();
SessionMgr sessionMgr = new SessionMgr();
EnterpriseSession enterpriseSession;
EnterpriseService enterpriseService;
InfoStore infoStore;
InfoObjects infoObjects;
InfoObject infoObject;
ReportAppFactory reportAppFactory;
string sampleReportName;
enterpriseSession = sessionMgr.Logon("administrator","","localhost","secEnterprise");
enterpriseService = enterpriseSession.GetService("InfoStore");
infoStore = new InfoStore(enterpriseService);
sampleReportName = "World Sales Report";
infoObjects = infoStore.Query("Select SI_ID From CI_INFOOBJECTS Where SI_NAME='" + sampleReportName + "' And SI_INSTANCE=0");
infoObject = infoObjects[1];
reportAppFactory = (ReportAppFactory)enterpriseSession.GetService("","RASReportFactory").Interface;
reportClientDocument = reportAppFactory.OpenDocument(infoObject.ID,0);
reportClientDocument = reportAppFactory.OpenDocument(infoObject.ID,0); code segment throws the Exception
modified on Tuesday, September 7, 2010 2:30 AM
|
|
|
|
|
Please clarify exactly which statement throws the exception and the full text of all messages produced by the exception. My guess is that the interface you are calling does not return the object type that you think it does.
It's time for a new signature.
|
|
|
|
|
reportClientDocument = reportAppFactory.OpenDocument(infoObject.ID,0);
throws System.InvalidCastException
Message is No such interfaces Supported
following is the stack trace
at CrystalDecisions.ReportAppServer.ClientDoc.ISReportAppFactory.OpenDocument(Object DocID, Int32 Options)
at BNPP.Reports.Common.GenerateBOReport.GenerateReport(String _reportName, String _fileName, String _repositoryName, String _fileExtention, Boolean& bolChechEmpty, Decimal minFileSize) in \GenerateBOReport.cs:line 146
|
|
|
|
|
From the information you provide I cannot see why it would throw this error. I suggest you try the documentation or contacting the provider of the library code for assistance.
It's time for a new signature.
|
|
|
|
|
infoObject = infoObjects[1];
Array indices in C# are 0-based. Shouldn't it be
infoObject = infoObjects[0];
instead ?
|
|
|
|
|