|
If I use software like OpenOffice and try to drag text I could notice that
1. when I drag inside the document I'm moving the text
2. when I drag outside the document I'm copying the text
Yet it all looks like one smooth operation. With correct cursor feedback (the little + marker next to the icon).
My problem is, once I call DoDragDrop() it's blocking, I have no other opportunities to change the AllowedEffect to only Copy if I drag over, say, an other control.
And QueryContinueDrag:
1. don't allow me to change the efect
2. don't inform me about the current drop target
How could I do that?
(i.e. how could I modify the allowed effect depending on the target (i.e. wether it's me or not))
|
|
|
|
|
Almost every component has a few drag/drop events which can be used to switch the allowed effects.
In your case you should use the DragLeave event to change the effect when the mouse leaves your form for example.
As long as the mouse hovers somewhere in your application you can do whatever you want with the DragEnter and DragOver events of each component that is under the cursor.
--------------------
Bertram Weckmann
www.svizzer.com
--------------------
|
|
|
|
|
You are wrong or I missed something.
DragEnter is only called on the target of drag and drop (not the source of the data) and the allowed effect can't be changed (as it is set by the source of the drag not the target), as the target can just the selected effect.
I need to change the allowed effect when I drag in other control/component, including other application. the dragenter is not the appropriaote event as it is something I need to do in the source of the dragging, not the destination
|
|
|
|
|
Well, when you start the dragdrop operation you can set the effects which are allowed. After that point it is up to the component over which the cursor is dragged which of these effects are shown. So if it is a component which does not belong to your application, you can only give it a set of effects and which of those will be chosen is up to the application.
I made a very very simple example:
http://g10.wilde-edv.de/PublicStuff/DragDropTest.zip
There you can drag the Button1 to the text field or to the button2. I set the allowed effects to copy and move. The button2 only accepts move and the text field only copy. So the icon is changed to the appropriate effect as soon as you drag over the control.
When you drag outside the form the other applications will pick either the copy or the move effect, or none if they do not accept the data.
Hope that helps.
|
|
|
|
|
Sorry I didn't explain my self vey well...
I would like to do something like that in the source:
// == pseuo code
if(source == this)
AllowedEffect = All
else
AllowedEffect = Copy
just like word.
when you drag text inside a word document it move it, if you drag to an other document it's a copy.
your sample don't address this issue at all.
In fact it seems you haven't realised yet that it is seemingly impossible with the public API of the control...
Thanks for trying to answer anyway
|
|
|
|
|
OK now Im trying to understand what you originally wanted.
The AllowedEffect has to be set at the beginning of the drag/drop operation. Afterwards it is read-only.
But nevertheless you can imitate the behaviour of Word:
Start the drag/drop operation with the allowed effects Move AND Copy.
Just fill the data in, but dont remove it yet from the source.
Then just set all target controls to allow ONLY Move and design the DragDrop event handlers in a way that the data is actually moved, so remove it from the source.
Now if the user drags it out of your application almost every other application will pick the copy effect because they dont have any drag/drop handler for a move operation from anything coming from somewhere else. And since you left the original data where it was at the beginning, everything done by other applications will be a copy operation.
And there is your Word behaviour. Inside your application you have a Move, outside you have a Copy.
Got you this time?
|
|
|
|
|
I am new hand to C#. I want to create a number of label(System.Windows.Forms.Label), like using lblMsg(0) in VB6 or m_lblMsg[0] in MFC++6, how can i do that ?
Can i use array to done this ? i tried using "lbl[0]", but has error message prompt by the IDE.
Thanks
|
|
|
|
|
What error did you get ? Did you define an array first ?
Your form has a Controls collection, you can put your labels in there ( you need to, to see them ) and you can iterate over the collection looking for labels, or store a reference in a seperate array if you prefer.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
i using following code to create the Label:
<br />
const int NUM_OF_LABEL = 64;<br />
private System.Windows.Forms.Label [] lblMsg = new System.Windows.Forms.Label[NUM_OF_LABEL];<br />
private void btnTest_Click(object sender, System.EventArgs e)<br />
{<br />
for(int i=0 ; i < NUM_OF_LABEL ; i++)<br />
lblMsg[i].Size=new Size(352, 288);<br />
}<br />
but when it execute, the following message prompt:
An unhandled exception of type 'System.NullReferenceException' occurred in docnettester.exe
Additional information: Object reference not set to an instance of an object.
Thanks your reply
|
|
|
|
|
stny2000 wrote: lblMsg[i].Size=new Size(352, 288);
lblMsg[i] is null, you created an array to hold objects, now you need to create a Label at each location.
And, like I said, you won't see these labels. They need to be added to the controls collection of the form. They also need a location, and text.
Christian Graus - C++ MVP
|
|
|
|
|
I can create it now and to the forms.
I forget to create the instance to the labels. i just create the instance of array...
Thanks a lot
|
|
|
|
|
Label[] lbl = new Label[10];
for (int i = 0; i < 10; i++)
{
lbl[i] = new Label();
}
|
|
|
|
|
I tried the code, but has following message prompt:
<br />
private void btnTest_Click(object sender, System.EventArgs e)<br />
{<br />
Label [] lbl;<br />
for(int i=0;i<64;i++)<br />
{<br />
lbl[i]=new Label();<br />
}<br />
}<br />
C:\docnettester\docnettester\Form1.cs(263): Use of unassigned local variable 'lbl'
thanks your reply
|
|
|
|
|
Label[] lbl = <big>new Label[10];</big>
for (int i = 0; i < 10; i++)
{
lbl[i] = new Label();
}
|
|
|
|
|
O....I know now...forget to create the instance for array
Thanks a lot
|
|
|
|
|
Greets everyone!
Am searching for a plugin or something else which allows me to communicate via C# (VS 2005) to a program which implements the CORBA interface. Have read about JANEVA, but Borland does not allow to download it any more. Which other possibilities are there? (I must admit at this very moment I have no idea how this should exactly work, hope it´s kind of dll which can be instanced. If anyone is experienced with this, I would really apreciate to read about this)
Thanks for your help.
|
|
|
|
|
so you want to communicate java systems with C# isnt' it ?
why don't u develop WSDL contracts implementing webservices ?
have you looked at those options ?
or am I missing something here?
Paresh
|
|
|
|
|
i created a static variable in a static class
for testing i stored around 50 MB data in it at runtime and then assign it to null
but the ram used is not freed even when i called Garbage collector
and when it replaced data with some other data the it just increased amount of ram used instead of freeing resources from the variable and load fresh data
|
|
|
|
|
i think i get the solution
there is a texture.dispose();
however the problem still exist that when i assign it to null then why don't the resources get free even after gc.collect
|
|
|
|
|
Amar Chaudhary wrote: gc.collect
This is always a bad idea.
The gc marks things according to how long they were in memory. If you held something for a while, it won't collect it necessarily, even if you call gc.collect. Dispose is the correct way to deal with objects that offer it.
Christian Graus - C++ MVP
|
|
|
|
|
How are you determining that "the ram did not get freed"? Are you looking at the CLR heaps? Or are you just expecting Task Manager to reflect the change (it won't)?
The only valid way to tell what is going on is to look at the CLR GC generation counts and the reachable/unreachable object counts. Once the CLR has to allocate more memory to the heap, it won't release it back to the OS until termination (unless the OS becomes starved for ram).
|
|
|
|
|
i did it with task manager
Rob Graham wrote: it won't release it back to the OS until termination
yes it may be so but when i dispose the same texture it reflects the changes (as i said i used 50 mb (approx) data )
and when i do
tex = new texture[0]; //it was a array of 10 or assign each individual item in it to null
and again assign the same thing in it the ram is increased by the same value every time
(in form ram+= )
and will you please guide me how to look at CLR heaps Thanks
|
|
|
|
|
TaskManager is not a very accurate tool when it comes to measuring managed memory consumption. As Rob said, you need to watch the CLR heap size instead. Perfmon (type perfmon.msc at the command prompt) has a set of counters that allow you to do precisely that. Right click on the graph, click "Add Counter", select ".NET CLR Memory" in the "Performance Object" drop down list and you'll see a list of managed memory parameters, which you can then select to monitor them for your process.
|
|
|
|
|
Setting an object null does not immediately cause it to be garbage collected, nor finalized (CLR calls dispose). Dispose is intended to release non-managed resources, independently of garbage collection, which is likely what you are seeing in TM when you call dispose yourself. when you set the array to null, or reallocate, the original array is de-referenced, and made elligible for GC. on the next GC cycle, it will be promoted to a second generation object, and be placed on the finalization queue. On the next collection, GC will call dispose (finalize) and collect the managed memory. So, sooner or later, GC would free memory that was allocated, but you can't predict when (which is why it is called non-deterministic). As Sentil said, use the CLR performance counters to observe GC actions.
This article[^] Has a good description of how all this works.
|
|
|
|
|
thanks this is very useful information wish more people to go through it
you have good knowledge of the topic why don't you write articles
|
|
|
|