I need some help with a sticky note project. I am teaching myself C# and thought a sticky note program would be a good chance to apply what I have seen in books. I have hit a snag which I am unable to work a way round.
I have a form which acts as my main program we'll call it frmMain. Eventually this will be displayed as a notification icon with context menu to add new postIT's. I have added and designed a frmPostIT which is the actual note (just richtext and a couple of labels and buttons). The frmMain has code to add new frmPostIT's as required - I am using:
frmPostIT frmChild = new frmPostIT();
frmChild.Show();
to initialise and display the new note.
This works fine but I intend using a database to store the information when the program is closed. I was going to save each postIT by using the FormClosing Method of my PostIT form. Again, I can do this fine.
The problem I have is, when the program opens, I want to open each saved postIT. I thought I could use the 'Load' event of frmMain to initialise the frmPostIT's, but am unable to pass anything to the textboxes on the newly created frmPostIT. So using the code sample above, I want to be able to do:
frmChild.richtextbox1.text = strNoteContents
but from frmMain I can not get to frmChild.richtextbox1
So how do I pass these values or should I create a class which both forms can access.... I'm struggling to understand Scope, especially with different forms/classes, so could you please explain in lay-terms where possible. I'd really appreciate any help and sorry in advance if its a really noob question. Thanks
3 replies to this topic
#1
Posted 06 December 2010 - 05:50 AM
|
|
|
#2
Posted 06 December 2010 - 06:03 AM
Looks like you declare richtextbox1 as protected or private. Therefore it's not accessible to frmMain. Declare it as public will solve your problem.
#3
Posted 06 December 2010 - 06:13 AM
lol, it was a noob question then. I just used the form designer without any thought given to how the controls are initialized. I found it in the frmPostIT.Designer.cs file.
Thanks for you help
Thanks for you help
#4
Posted 06 December 2010 - 06:17 AM
You're very welcome.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









