|
|
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?
|
|
|
|
|
To add a new control, use this.Panel1.Controls.Add( {yourNewControl} )
"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've made this code:
<br />
PictureBox pic = (PictureBox)sender;<br />
pic.Image = (Bitmap)e.Data.GetData(typeof(Bitmap));<br />
this.panGameDesign.Controls.Add(pic);
But it doesn't work and doesn't create it where the mouse button is let go, could someone help me edit it?
|
|
|
|
|
your code:
- did not create a new control (there is no creational method called, no new keyword used,...);
sender can not possibly point to a Control that does not yet exist, it refers to
the old PictureBox at best.
- did not add the new control to your form's Controls collection, it tried to add an existing
Control to the form's Controls collection again
- did not set the location of the new control
- did not set the size of the new control
- did not insert the image in the new control, it did set it in the old control (which does
not change it).
You will have to add/modify one or more lines of code to solve each of the above shortcomings.
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.
|
|
|
|
|
PictureBox pic = new PictureBox();<br />
pic.Image = (Bitmap)e.Data.GetData(typeof(Bitmap));<br />
pic.Size.Width = 32;<br />
pic.Size.Height = 32;
As you can see, this won't work because I'm new to this sort of coding (I'm at a beginner level) and this is the best I can do as I do not know many complex commands.
I can't quite get my head around this, could someone correct it for me?
|
|
|
|