|
Noooo - please don't pass values between forms. Instead, consider using a suitable design pattern such as MVC to manage the interaction instead. Your phone number is part of the model; the forms are the views. Trust me - you'll be a better developer at the end of this journey.
|
|
|
|
|
I was looking at the article and I don't think that will do what I want it to anyways. I'm very confused on this. Mainly because the EnterInformation form is part of the access database. It seems like everyone passes it when opening the form as in Form form = new EnterInformation(string PhoneN). I cannot have the form reload like that because then the Fill will occur. I don't know if I explained that quite well.
I need it to pass the text to the EnterInformation (which is already open, and I do not want to perform a new EnterInformation).
|
|
|
|
|
I'll explain the MVC pattern and you can see how it is applied. Basically you have a datamodel which includes the phone number. There's a controller which is responsible for actually changing the value based on user input - and when the model changes, the attached views are updated by the controller. To do this update, you'd typically use an Update method which updates the view based on the values in the model. As a hint, you're probably going to need an event or two in here as well. I'm not actually going to write the code for you - you've got enough information now to do some research in google and have a stab at your version.
|
|
|
|
|
I think I get what you are saying... I will see what I can find.
|
|
|
|
|
|
That talks about passing from two open forms that is a parent and a child... what about two open childs?
|
|
|
|
|
Jacob Dixon wrote: what about two open childs?
I think it is still the same. Pete's idea of using MVC is a very good way to go as well.
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
The same article has discussed this topic at the end, named "Sibling to Sibling" if you scroll down at the end.
|
|
|
|
|
As Pete indicated, you really need to implement a design pattern that will meet your need.
The MVC Pattern is one approach and will work if you have two forms within a single application space.
The Publish/Subscribe Patter is another approach that is basically a very loosely bound MVC pattern.
When each form becomes active, they will contact the data manager and subscribe an EventHandler for any time that data changes.
When one form sends a message to update something (like phone or description) then once the change is finished an event is raised that notifies all parties that the data changed.
The event handler can pass an object which will indicate what changed, and what the value is now. Each subscriber looks at the object, determines if it applies to them, then changes what they are displaying (changing the view as Pete described it).
This is the only VALID way that you can have one form reflect changes that another form has done.
|
|
|
|
|
That is the article I already referred Jacob to earlier.
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
Yes it is now that I look at it... in the article it says: Parent to child... on his website it says passing from one open form to another. Anyways I still have to do some research. Its over my head.. my problem is, is that I'm trying to develope a program that is past my knowledge lol. I guess that is the only way you will learn though. I'm ordering some more books because the books I was talking about going to get from Barnes and Noble are not in the stores in Arkansas. There are two of them I am buying.
Wrox C# Databases
Wrox Beginning C#.
Somehow I ended up with C# with .NET which is the advance one.. I should have gotten the other two before the one I actually have now lol. I read the entire Deitel C# 2005 How to program, but I do not recall it talking about anything I am trying to do here.
|
|
|
|
|
I am trying to create a progam that will contain a small web browser in a seperate form. Now it HAS to be on another thread because the user still needs to be able to accsess the first form, So ShowDialog can't be used. When I compile it and run it to test it, it gets as far as clicking the button that opens the browser. Thne it lags and VC# 08 shows me where the error is.
The error is:
ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
Can anyone help me here?
|
|
|
|
|
I'm no expert with DirectX, but is what you are trying to do thread-safe?
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
I don't know. All there is in the form is the standard window and buttons, a webrowser control, a button, and a text box. You type in a url hit the button and the site shows up in the web browser control. That is all that happens in the thread so far. I might implement a back refresh button etc.
EDIT: What it mean by a single threaded apartment?
(seems like an oxymoron.)
modified on Sunday, January 27, 2008 4:53:52 PM
|
|
|
|
|
Hi,
try inserting a Thread.SetApartmentState() when you create the new thread, and before you
have it do the Form and Browser stuff.
There are basically three states:
Single, Multi, and Undefined; it is related to how COM obect accesses are serialized.
Threads start off in Undefined, can be set Single or Multi (but only once), and must be
Single for some operations to succeed, and Multi for maximum performance. It is a rather
complex matter, don't worry until you really have to.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
it gives me this:
No overload for method 'SetApartmentState' takes '0' arguments
|
|
|
|
|
You are allowed to read the documentation on the classes and methods you intend to use.
I just told you there are basically three states, so naturally a SetState() method would
need an argument.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
DOH! Thanks. I feel so stupid now.
|
|
|
|
|
Mabre of the Tadadas wrote: I feel so stupid now
Don't. Just read and learn, read and learn. All the time. Look around, experiment, ask
questions, move ahead. Don't feel anything, stupid, smart, whatever, it won't improve your code,
until you discover the beauty of some patterns, you'll know when you get there.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
|
I've made a small application where you can drag an image from a picture box into a panel, but I want to create a picturebox where the user lets go off the left mouse button and has the picture they dragged into it (this will be in the DragDrop Event)
Can anyone help?
|
|
|
|
|
Do you have any code to show where you are having trouble?
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
private void panGameDesign_DragEnter(object sender, DragEventArgs e)<br />
{<br />
if (e.Data.GetDataPresent(typeof(Bitmap)))<br />
{<br />
e.Effect = DragDropEffects.Copy;<br />
}<br />
else<br />
{<br />
e.Effect = DragDropEffects.None;<br />
} <br />
}<br />
<br />
private void panGameDesign_DragDrop(object sender, DragEventArgs e)<br />
{<br />
}<br />
<br />
private void picMario_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
picMario = (PictureBox)sender;<br />
DoDragDrop(picMario.Image, DragDropEffects.Copy);<br />
}
The Do Stuff is what I'm having trouble with, I've no idea what code to use so I cut it out and left a comment.
|
|
|
|
|
I think you have to create a new picturebox control in the DragDrop event, after that, you copy the dragged picture into the newly created control in the panel. I could be wrong, but that is first thing coming to mind...
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
That's what I thought but I don't know the code to do that.
I wanted it to create a picturebox with the dragged picture where the user lets go of the left mouse button.
Does anyone have the code or could someone give it too me?
|
|
|
|