|
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?
|
|
|
|
|
you got a bit closer.
check your code again with my list of requirements.
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.Width = 32;<br />
pic.Height = 32;<br />
pic.Top = Cursor.Position.X;<br />
pic.Left = Cursor.Position.Y;<br />
this.panGameDesign.Controls.Add(pic);
Even closer, this is my own code, it works but it creates the picture box in a random position in the panel.
|
|
|
|
|
From the documentation:
Cursor.Position gets...a Point that represents the cursor's position in screen coordinates
Control.Top ... gets or sets the distance, in pixels, between the top edge of the control and the top edge of its container's client area
So I don't think the position is random, but I am sure it is not what you want either.
If used correctly, Control.PointToClient() should help you.
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 replaced the old placement code with:
pic.Location = this.PointToClient( new Point (e.X, e.Y) );
It creates it nearer to the mouse but not at the exact X and Y of the mouse...
I solved it, it was panGameDesign.PointToClient(); not this.PointToClient();
Thanks for the help
modified on Sunday, January 27, 2008 3:32:20 PM
|
|
|
|
|
I haven't done DragDrop myself lately, and you are not providing much detail on the deviation,
but maybe you could/should use DragEventArgs.X/Y instead of Cursor.Position
Try to find out how the deviation relates to other stuff, such as:
- where exactly you click the source image,
- peculiarities of the PictureBox; what BorderStyle and SizeMode do you use on both?
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.
|
|
|
|
|
Luc Pattyn wrote: I haven't done DragDrop myself lately
Same here. Did some a while back, about 3-4 months ago.
"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
|
|
|
|