473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to replicate the ItemDrag event

I have a bunch of colors as preferences in my application (Title
color, text color, border color, etc...). I'd like the option to copy
a color from one parameter to another by dragging the first color and
dropping it in the second color parameters space.
My question is how do I replicate the ItemDrag event that starts the
whole thing off? I'm stuck using either Buttons or PictureBoxes (due
to the need to display the selected color to the user). So how do I
replicate the ItemDrag event in an object that doesn't support it?

Tom P.
Aug 1 '08 #1
5 3301
On Aug 1, 4:04*pm, "Tom P." <padilla.he...@gmail.comwrote:
I have a bunch of colors as preferences in my application (Title
color, text color, border color, etc...). I'd like the option to copy
a color from one parameter to another by dragging the first color and
dropping it in the second color parameters space.
My question is how do I replicate the ItemDrag event that starts the
whole thing off? I'm stuck using either Buttons or PictureBoxes (due
to the need to display the selected color to the user). So how do I
replicate the ItemDrag event in an object that doesn't support it?
I'm not sure what you mean by "replicating ItemDrag". ItemDrag is a
special event for controls which are containers of items (which are
not controls), and you have to detect dragging of a particular item.
For plain controls, you can just use MouseDown/MouseMove as usual -
basically, you should detect that user has pressed the mouse button
down, and has moved the mouse while still holding the button so that
the distance passed by mouse cursor is larger than
SystemInformation.DragSize. At that moment, you can invoke DoDragDrop,
and the rest is all the same.
Aug 1 '08 #2
On Aug 1, 7:43*am, Pavel Minaev <int...@gmail.comwrote:
On Aug 1, 4:04*pm, "Tom P." <padilla.he...@gmail.comwrote:
I have a bunch of colors as preferences in my application (Title
color, text color, border color, etc...). I'd like the option to copy
a color from one parameter to another by dragging the first color and
dropping it in the second color parameters space.
My question is how do I replicate the ItemDrag event that starts the
whole thing off? I'm stuck using either Buttons or PictureBoxes (due
to the need to display the selected color to the user). So how do I
replicate the ItemDrag event in an object that doesn't support it?

I'm not sure what you mean by "replicating ItemDrag". ItemDrag is a
special event for controls which are containers of items (which are
not controls), and you have to detect dragging of a particular item.
For plain controls, you can just use MouseDown/MouseMove as usual -
basically, you should detect that user has pressed the mouse button
down, and has moved the mouse while still holding the button so that
the distance passed by mouse cursor is larger than
SystemInformation.DragSize. At that moment, you can invoke DoDragDrop,
and the rest is all the same.
The steps you outlined are what I meant. I didn't realise I could
invoke DoDragDrop when not in a dragdrop event, I'll have to see if
there's enough information at that time. Now to figure out how to tell
if the mouse has moved farther than DragSize (Basically how to compare
a linear measurement to a co-ordinate measurement).

But thanks for the DoDragDrop tip. I just didn't realize.

Tom P.
Aug 1 '08 #3
On Aug 1, 4:54*pm, "Tom P." <padilla.he...@gmail.comwrote:
The steps you outlined are what I meant. I didn't realise I could
invoke DoDragDrop when not in a dragdrop event, I'll have to see if
there's enough information at that time. Now to figure out how to tell
if the mouse has moved farther than DragSize (Basically how to compare
a linear measurement to a co-ordinate measurement).
DragSize is actually an instance of struct Size, so it defines Width
and Height of the drag rectangle - if horizontal mouse delta is larger
than Width, or if vertical delta is larger than Height, then it's time
to start dragging.
Aug 1 '08 #4
On Aug 1, 8:56*am, Pavel Minaev <int...@gmail.comwrote:
DragSize is actually an instance of struct Size, so it defines Width
and Height of the drag rectangle - if horizontal mouse delta is larger
than Width, or if vertical delta is larger than Height, then it's time
to start dragging.
I got it!

Thanks for the help. I had to do a (old.X - new.X >= DragSize.Width)
|| (old.Y - new.Y >= DragSize.Height).

And the dragdrop was exciting. (I am posting it for those looking to
figure this bloody technology out. It was hard enough to find I hope
this helps others.)

Once you have established that you are dragging (see above) you do the
following:

DataObject tempDataObject = new DataObject(this.BackColor);
DoDragDrop(tempDataObject, DragDropEffects.Copy);

This creates a DataObject and stores the data you want to pass to the
drop target in it (in my case a Color object). This is the only method
that you look at from the "draggers" point of view. The other events
are fired by the Drop target (don't forget the drop target could be
the same as the object that started the drag so it might look
confusing).

Then, in the DragEnter and DragOver events you check your object and
make sure you are accepting the data that is being dragged by checking
the DataFormats like so...

List<stringlstTest;

lstTest = new List<string>(drgevent.Data.GetFormats());

if (lstTest.Contains("FileDrop"))
{
//If you want to do different things based on different keys then
check those too..
if ((drgevent.KeyState & 8) == 8)
{
drgevent.Effect = DragDropEffects.Copy;
}
else
{
drgevent.Effect = DragDropEffects.Move;
}

}

Then, in the DragDrop event you get the object out of the DragObject
structure...

List<stringItemFormats;

ItemFormats = new List<string>(drgevent.Data.GetFormats());

if (ItemFormats.Contains("System.Drawing.Color"))
{
this.BackColor = (Color)drgevent.Data.GetData(typeof(Color));
}
Then process the data any way you feel you need to.

Hope this helps others.
Tom P.
Aug 1 '08 #5
On Aug 1, 9:11*pm, "Tom P." <padilla.he...@gmail.comwrote:
if (ItemFormats.Contains("System.Drawing.Color"))
{
* * *this.BackColor = (Color)drgevent.Data.GetData(typeof(Color));

}
Note that IDataObject.GetData() returns null if such type was not
found, so you typically just ask for the type and check for null - no
need to do GetFormats()/Contains(). If you need to check whether the
data is of a given format without retrieving it,
IDataObject.GetDataPresent() is probably still more efficient.
Aug 1 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Glynn Johnson | last post by:
I understand that there is no way to upload multiple files using ASP and COM+ without having multiple form elements like <input type='file'>. I also understand that there is no way to...
3
by: jaekim | last post by:
Hi. I am wondering if it is a good idea to replicate sql server db files using frs. I don't really know how the frs works, so does frs replicates the whole database from time to time or just...
2
by: db2group88 | last post by:
we are using db2 udb v8.2 Express edition on windows 2003,we use third party vendor software to help replicate one server to another. Production server has three instances, each instances has one...
6
by: Stanley Sinclair | last post by:
Can I "replicate" from a flat file which changes, but is not a part of a formal database?
0
by: Paul Hobbs | last post by:
Hi All, I am trying to replicate the functionality of the HTML FileField control. I can use it just fine to prompt a user to browse to a file, and it retrieves the full path just fine. I can...
0
by: Paul Hobbs | last post by:
Hi All, I am trying to replicate the functionality of the HTML FileField control. I can use it just fine to prompt a user to browse to a file, and it retrieves the full path just fine. I can...
0
by: Joseph Geretz | last post by:
This project is a collaborative effort. We need to have this project environment up and running on multiple developer workstations. I'm trying to replicate the environment on a second workstation...
6
by: Michael.Suarez | last post by:
Consider the TextBox Control. It has a KeyPress event of type KeyPressEventHandler which passes a KeyPressEventArgs to whatever method is assigned to the event. When you set e.Handled = false...
1
by: mg | last post by:
Is there a way to replicate the GAC on a win2003 server to another similar server? We are currently using DFS to replicate files, and I do not see how to use DFS to replicate the GAC. -- mg...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.