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!
6 4407 @IanWright
Handle the NodeMouseClick of treeview & form's mousemove events.
Few lines of code is shown below.You can enhance it. - private void treeView2_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
-
{
-
tracked = true;
-
start.X = treeView2.Location.X + e.Location.X;
-
start.Y = treeView2.Location.Y + e.Location.Y;
-
}
-
private void Form1_MouseMove(object sender, MouseEventArgs e)
-
{
-
if ((tracked == false) || (e.Button != MouseButtons.Left))
-
{
-
return;
-
}
-
end = e.Location;
-
Pen pen = new Pen(Color.FromArgb(96, 155, 173), 1);
-
this.Refresh();
-
Graphics g = this.CreateGraphics();
-
Rectangle rc = new Rectangle(start, new Size(start.X - end.X, start.Y - end.Y));
-
g.DrawLine(pen, start, end);
-
System.Diagnostics.Trace.Write("in mousemove\n");
-
g.Dispose();
-
}
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
@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.
@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 ...
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
| |