|
Rabbit17 wrote:
public void printDecision()
{
mainform.MainForm_UpdateText();
}
But where has mainform been assigned to an instance of MainForm? That's where your problem is, you need to somehow pass an instance of MainForm to MainApp, if you want to call methods/properties on MainForm. I'd suggest adding a property to MainApp, something like
class MainApp
{
public static Form MainForm
{
set { mainForm = value; }
}
}
class MainForm
{
...
public MainForm()
{
...
MainApp.MainForm = this;
}
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Okay, I did that... yeah sometimes the basics are so overlooked... now it doesn't update. But at least it compiles now! This is my code on the MainForm:
public void textBox11_TextChanged(object sender, System.EventArgs e)
{
}
public void MainForm_UpdateText()
{
textBox11.Text = MyApp.finalDecisionString;
}
and I call MainForm_UpdateText() from the MainApp with:
public void printDecision()
{
MainForm dummy;
dummy = new MainForm();
dummy.MainForm_UpdateText();
}
So I guess my question is if the textbox can only be changed by an object sender, how can I make sender something internal instead of a user click?
|
|
|
|
|
Rabbit17 wrote:
public void printDecision()
{
MainForm dummy;
dummy = new MainForm();
dummy.MainForm_UpdateText();
}
This is not going to work. You're creating a new instance of MainForm, so changing the textbox value in that form is not going to reflect in the original form. You need to have some property exposed by MyApp, that is set in the MainForm's constructor (see my previous post). You'll then call MainForm_UpdateText() on that instance, which will do what you want.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I'm fairly new so this is probably a dumb question.
My App generates various data in class files away from the form class that have nothing to do with any additional user input. Basically, they start the app and it makes calculations.
My question is, how do I get the output to display somewhere on the form. I tried using textboxes, but that was a bust because I couldn't reference them without it bombing out. Apparently they are mainly for users inputting text, not seeing displayed text.
Thanks,
RABB17
|
|
|
|
|
Don't reference the form, or textbox, in the class; reference the class in the form.
Form1_CalculateButtonClick()
{
MyClass cls = new MyClass();
Textbox1.Text = cls.DoCalculation();
}
|
|
|
|
|
I tried your code above but it didn't help. It does makes sense, but once my app is started it is constantly running and gathering data from other apps and therefore it only initializes the Mainform once.
If I do try to reference the form I get this error:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
Any further ideas? Thanks!
RABB17
|
|
|
|
|
All you have to do is set the Text property to whatever string you need to display the results.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have created a basic setup project to install several files. One of the files is a batch file that makes a RASDIAL call to a specific Dial Up Connection in Network Connections. If possible I would like to automate the creation the Dial Up connection if it does not exist during the setup process.
Is this possible ? Is there a way for creating a template or file that can just be placed in a specific location that will be viewed by the system as the dial up connection ?
-> Installatoi Intended for a WinXP system
-> Using the .NET Enviroment
Thanks
Clint
|
|
|
|
|
how to send files(eg powerpoint slides) from server to client
|
|
|
|
|
I am having some very strange problems with ArrayList in a class I've written. When I create and populate an ArrayList, only the odd indexes are populated, and the evens are no where to be found. When I try to iterate through the list, it fails on the first index with an "Object not set to an instance" error (since index 0 is technically even). If I start on index 1, it succeeds, but fails when it gets to index 2.
When I watch the ArrayList in VS.NET's debugger, I get a list like this:
list - {Count(5)}
[1] - object 0
[3] - object 1
[5] - object 2
[7] - object 3
[9] - object 4
When it should be this:
list - {Count(5)}
[0] - object 0
[1] - object 1
[2] - object 2
[3] - object 3
[4] - object 4
Has anyone ever encountered something like this before? Any ideas what could possibly be causing such odd behavior with the ArrayList object? Thanks for any help.
|
|
|
|
|
Without seeing your source I can't say for certain, but at a guess you're incrementing the index you add at both before and after you insert an element into the array.
|
|
|
|
|
How are you populating the ArrayList? Using the constructor that takes an ICollection as parameter?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
ArrayList list = new ArrayList();
foreach (obj in objectarray)
{
list.Add(obj);
}
return list;
Thats basically it. I'm not doing anything special, or out of the ordinary. I'm just using the arraylist at its most basic level.
|
|
|
|
|
Very strange. What exception do you get when you try to access index 0?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
From the c# programmer's reference:
The foreach statement repeats a group of embedded statements for each
element in an array or an object collection. The foreach statement is used to
iterate through the collection to get the desired information, but should not
be used to change the contents of the collection to avoid unpredictable side
effects. The statement takes the following form.....
If you change the collection, the iterator is no longer valid.
[the first time I posted this, I accidentally replied to S. Senthil Kumar. sorry for the mistake]
[P.S. I actually did reply to Jon Rista this time, but it still shows as a reply to S. Senthil Kumar. I don't know what I can do.]
|
|
|
|
|
Well that's true, but he is iterating over an object array and is changing the newly created ArrayList so this shouldn't be the problem...
|
|
|
|
|
Sorry, I must have read what I thought he was saying rather than than the actual code. I'll have to get these glasses checked!
|
|
|
|
|
Is it possible the the objectarray contains null values?
Try this:
ArrayList list = new ArrayList();
foreach (obj in objectarray)
{
if (obj != null)
list.Add(obj);
}
|
|
|
|
|
Even in that case, he should be getting null values when he indexes into the array, not exceptions.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
That's right, but I assume he didn't just iterate but also tried to call some method on those elements.
|
|
|
|
|
There were nulls in the arraylist. I was populating it by traversing a RedBlack Tree (similar to a B-Tree), and I forgot to check for the nil nodes. Once I added the check for nil nodes in, the problem was solved.
I guess that if you add nulls to an ArrayList, adding a watch on that ArrayList will only show the non-null components. The thing that I still don't understand is why I keept getting an exception when I tried to retrieve the elements. Even if the element was null at a given index, I should get a null result, not an exception. Regardless, the problem is solved now. Thanks for all the replies.
|
|
|
|
|
Ok, i have finished my project. i wanna send it to a friend. what do i do. with visual studio 6, there was (make exe file). how do u do that with .net?
thanx in advance.
|
|
|
|
|
|
and where do i find that?
|
|
|
|
|