473,387 Members | 3,033 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,387 software developers and data experts.

Linking between Form Controls (Drag Events)

179 100+
I'm trying to test something to see if its functionally possible, and am having a little trouble with drag events...

I basically want to draw a line between two TreeNode entities, contained within two seperate Treeviews.

I can override the Paint method and draw a link between the last selected Node and the current mouse position (set on the Forms MouseMove), but this only works when I'm not dragging/dropping.

The functionality I need, is MouseDown over a node, start dragging to other treeview, a line is drawn from the edge of the Treenode following the mouse, then when releasing the mouse on another treeview, this line attaches to it's bounding box too.

Does anyone have any suggestions as to which Control's events I need to be using, as it's feeling that I can't quite do it in the way I expected...

Thank you!
Dec 19 '08 #1
6 4407
Ramk
61
@IanWright
Handle the NodeMouseClick of treeview & form's mousemove events.
Few lines of code is shown below.You can enhance it.
Expand|Select|Wrap|Line Numbers
  1. private void treeView2_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  2.         {
  3.             tracked = true;
  4.             start.X = treeView2.Location.X + e.Location.X;
  5.             start.Y = treeView2.Location.Y + e.Location.Y;
  6.         }
  7.         private void Form1_MouseMove(object sender, MouseEventArgs e)
  8.         {
  9.             if ((tracked == false) || (e.Button != MouseButtons.Left))
  10.             {
  11.                 return;
  12.             }
  13.             end = e.Location;
  14.             Pen pen = new Pen(Color.FromArgb(96, 155, 173), 1);
  15.             this.Refresh();
  16.             Graphics g = this.CreateGraphics();
  17.             Rectangle rc = new Rectangle(start, new Size(start.X - end.X, start.Y - end.Y));
  18.             g.DrawLine(pen, start, end);
  19.             System.Diagnostics.Trace.Write("in mousemove\n");
  20.             g.Dispose();
  21.         }
Dec 20 '08 #2
IanWright
179 100+
Ramk,

Thanks for the reply. I actually believe that was the same I was doing before but the MouseMove event does not get thrown on the form while 'Dragging'... or at least it didn't seem to in my case.

Only thing I was really doing differently was I was causing Invalidate... as I never actually knew about the CreateGraphics method.

I'm guessing also that Rectangle was a mistake, seeing as you're not using it :P
Dec 22 '08 #3
Ramk
61
@IanWright
Did you check the mousemove event is attached to the form? Other case could be, a panel could have occupied the entire form, in which the mouse move messages will go to the panel when the mouse is over it.

CreateGraphics will create the graphcis object for us, through which we can draw on the screen irrespective of the underlying graphics hardware.

Yes, the rectangle is unnecessary. I want to comment it by editing my post, but thought, it won't harm much & kept as it is.
Dec 23 '08 #4
@IanWright
I've run into this same problem. To restate what you've already said: if you check the MouseMove event normally over multiple controls, the event is thrown for each particlar control. However, if you MouseDown over one control, drag the mouse over other controls, the MouseMove event is thrown but the object throwing it is the original control that contained the MouseDown event.

I'm trying to drag information from one control to the next but no MouseMove event is thrown for the next control ...

I could hack around it but would prefer a more straightforward solution.

I'll post it if I find it ...
May 21 '09 #5
Found a solution ...

I needed to disable the drag drop feature. I had thought of this previously and the method to do this is AllowDrop but when you try to set AllowDrop my compiler tells me I can only "get" and not "set" AllowDrop.

Well apparently, you can't set the AllowDrop of your base Form or UserControl, but you can set AllowDrop of controls you've added to your base Form or UserControl.

this->controlName->AllowDrop = false;

Now all the mouse events are raised while holding your mouse buttons down ...

BTW, my compiler is Visual C++ .NET 2005.
May 21 '09 #6
umaram
1
Hi,

I have a requirement to draw between to treeview in a form in c#. Could you please give the code sample to proceed?

Thanks in advance
Jul 30 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Scott McChesney | last post by:
I'm writing a Windows application for a client, and I've run into a problem I don't know how to solve. The UI is relatively simple - a listbox on the left (in a panel), and a third-party tab...
4
by: zav | last post by:
Hi all i`m having a small problem with windows forms, i`m attempting to provide the following functionality to a form. Ability to drag and drop another form onto a form and then to dock this...
7
by: MuZZy | last post by:
HI, We have a pretty large application with hundreds of forms in it. Now some of our new clients request us to make some custom screens(forms), which basicly comes to rearranging controls on our...
0
by: Pat Sagaser via .NET 247 | last post by:
I'm using a repeater with a dynamic template. I don't know the fields to display (or how many) until runtime. I have everything working except for linking Button events to the repeaters ItemCommand...
4
by: Dino M. Buljubasic | last post by:
I have a form and a panel on the form that holds 24 user controls each one representing an hour (0 - 23). The panel is completelly covered with the user controls. I need to be able to select...
5
by: Dino M. Buljubasic | last post by:
I am trying to build a daily calendar similar to Microsoft Outlook where a user can select hours of a day using mouse. I have a form that holds a panel which contains user controls each...
2
by: Jason | last post by:
Hello I've created a form that serves as a front end for a DB. My question is how to resize the form, and have the control on the form resize themselves as i drag the form. I've got a status...
9
by: Rob | last post by:
When a custom control is used within a form, that control does not get events directly. I've run into this a couple times with both mouse and keyboard events. Ex: A custom control inherits from...
0
by: raghunadhs | last post by:
Hi all! i am developing an application in v.b 6.0. it consists of some user controls (developed by using Activex controls...)... I am able to drag and drop the user contols on the screen and these...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.