|
Hi,
I am fairly new at C# and Windows programming. I am a bit confused why the TreeView has a ContextMenu property when you can not really use ContextMenu_Popup Handler when it does not accurately give you the mouse coordinates. OK I am not being clear, take this code for example:
private void ContextMenu_Popup(object sender, System.EventArgs e)
{
TreeNode node = TreeView.GetNodeAt(PointToClient(Cursor.Position)) as TreeNode;
if (node == null)
return;
ContextMenu.MenuItems.Clear();
ContextMenu.MenuItems.Add(node.Text);
}
When right clicking on a node this pops up the context menu but the node that it displays is (on my app) 80 pixels lower.
On looking through the forums I see that people tend to use something more like this:
private void TreeView_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
TreeNode node = TreeView.GetNodeAt(e.X, e.Y) as TreeNode;
if (node == null)
return;
ContextMenu.MenuItems.Clear();
ContextMenu.MenuItems.Add(node.Text);
}
}
My questions is why even have a ContextMenu property if it does not work. I am probably just missing something obvious. But thanks anyway to any who reply.
Sean
|
|
|
|
|
Sorry, I think I just figured it out. I still have to have the ContextMenu set in order for it to display. So let me rephrase the question. Why do I have to do the processing in MouseUp rather than in Popup? Is there a way to get the accurate mouse information from the ContextMenu_Popup method?
[UPDATE]
Never mind, I broke it again somehow using the MouseUp so I have no clue what I am doing anymore or what I am asking or what I am thinking or anything. I think I need to step away from the computer for a bit...
Sean
-- modified at 14:48 Friday 11th November, 2005
|
|
|
|
|
Your first attempt looked the best. All that you were doing wrong was converting the point to the client coordinates of the Form rather than the client coordinates of the TreeView. I'm guessing the 80 pixels off the mark was because your tree view is 80 pixels from the top of the form.
Point rawCursorPosition = Cursor.Position;
Point clientCursorPosition = TreeView.PointToClient(rawCursorPosition);
TreeNode node = TreeView.GetNodeAt(clientCursorPosition) as TreeNode;
Does this help?
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
Yes it did help. Thank you very much. One question I do have though is, is it better to use the MouseDown/MouseUp events or the Context_Popup event for context menus? Most examples I see seem to use the MouseDown (which I find a bit odd since most Windows Apps use MouseUp...Windows Explorer for example) Yet I would think the Popup would offer the least overhead... I don't know, just curious which is why I asked.
Thank you once again.
Sean
-- modified at 12:34 Monday 14th November, 2005
|
|
|
|
|
|
|
Hi.
I was just playing around but got into some trouble.
I created a form (f1) with a button. I want that when the button is clicked that another form (f2) springs up with some control on it (a label or another button) and I also want to be able to draw a string or a line on that form (f2). How do I do that? The line I draw is always on f1 but not on f2? I had no problem putting a Label control on f2 but drawing a simple line on f2 just beats me!
Can someone please help me?
Thanks,
FJ
|
|
|
|
|
Override the OnPaint method of f2 and draw your line there.
|
|
|
|
|
Thanks for answering but I am not following you
This is what I did when the button on f1 is clicked:
private void button1_Click(object sender, EventArgs e)
{
Form f2 = new Form();
f2.Show();
Label l = new Label();
f2.Controls.Add(l);
l.Location = new Point(30, 30);
l.Text = "Hello";
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Black, 2);
Point p2 = new Point(50, 70);
Point p3 = new Point(50,100);
g.DrawLine(p, p2, p3);
}
The line is drawn on the underlying form (f1) but not on f2 like I wanted it to be.
Regards,
FJ
|
|
|
|
|
naglbitur wrote: protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Black, 2);
Point p2 = new Point(50, 70);
Point p3 = new Point(50,100);
g.DrawLine(p, p2, p3);
}
This should be in the class of f2 not f1. But since you are using a generic Form instead of creating a new class that inherits from Form I guess you could hook the f2.Paint event and do your drawing there. Something like this:
<code>
f2.Paint += new new PaintEventHandler(f2_Paint);
.
.
.
private void f2_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Black, 2);
Point p2 = new Point(50, 70);
Point p3 = new Point(50,100);
g.DrawLine(p, p2, p3);
}
</code>
|
|
|
|
|
I'm currently working on a project where I have to send live stream from an usb webcam. I was able to view the webcam using DirectShowNET.dll, but I wasn't able to send the stream through tcp/ip. If anyone know how to do this please please show me the way.
Thank you very much.
email: toan1981@hotmail.com
|
|
|
|
|
Hi!
I need to raise some event dynamically through Reflection.
So I get the EventInfo but my EventInfo.GetRaiseMethod() allways returns null no matter i use the parameters true, false or none.
I saw several guys with this problem, but no solution.
Any ideas? Workarounds?
Thanks,
vSoares
|
|
|
|
|
|
There is an article for putting a progressbar in the taskbar ( http://www.codeproject.com/useritems/taskbarctrl.asp?msg=1263806#xx1263806xx ) and I was wondering if this can be done in C#. If so, can somebody help me out. I posted in that article, but nobody has gotten back to me. Any help would be appreciated!
Thanks
JGA
|
|
|
|
|
Not trying to be mean, but the author got back to you. You should start rewritting the code in c# and post specifics about what is not working. He is allowing you an entire working source code, and you just have to translate it. I do not understand what more you want.
*****************
"We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
|
|
|
|
|
Dwayner79 wrote: I do not understand what more you want.
He want someone to do his work for him.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
I just need a start. His example does not even work on my computer so why would I try and convert code that doesn't work on my computer? I've done a lot of research and I just need to know how to get it started.
|
|
|
|
|
Hello,
How can I dump a datagrid values into a text, or csv files?
Thank you.
|
|
|
|
|
Is your DataGrid bound to a dataset? If so, use DataSet.WriteXML() to write the info out to an xml file. If it is bound to a DataTable, I would add the table to a DataSet and use the above command. XML files can then be opened by word or excel or whatever. If not, then you need to use foreach loops and manually write out the data.
|
|
|
|
|
Hi. I am using SharpZipLib in order to compress a text file. The compression works fine, but when I try to decompress, sometimes I get an error "Error baseInputStream GZIP header, first byte doesn't match". Below is the code I use to decompress:
GZipInputStream gzipInputStream = new GZipInputStream(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read));
string tempPath = Path.GetTempFileName();
FileStream fileOutputStream = new FileStream(tempPath, FileMode.Open, FileAccess.Write, FileShare.None);
while(gzipInputStream.Available > 0)
{
byte b = (byte)gzipInputStream.ReadByte();
if(gzipInputStream.Available > 0)
fileOutputStream.WriteByte(b);
}
gzipInputStream.Close();
gzipInputStream = null;
fileOutputStream.Close();
fileOutputStream = null;
File.Copy(tempPath, path, true);
File.Delete(tempPath);
Does anyone know what I'm doing wrong?
Thanks
|
|
|
|
|
Depending on the userControl currently loaded, I want to capture the F1 and open up the help file to the section associated with that control.
I have the F1 captured and opening the help file to the main screen.
Here is my current code:
string HelpFileName = Application.StartupPath + @"\Help\PC3_Setup.chm";<br />
helpProvider1.HelpNamespace = HelpFileName;<br />
<br />
Help.ShowHelp(this, helpProvider1.HelpNamespace);
I do not want a tool tip or a pop up, I actually want to jump to the section of the help that is being worked on.
Thanks in advance...
*****************
"We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
|
|
|
|
|
Here is the answer in case it comes up in the future.
Help.ShowHelp(this, helpProvider1.HelpNamespace, HelpNavigator.Topic, @"whateverthishappenstobe.html");
*****************
"We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
|
|
|
|
|
Hello,
Is it possible to populate the range of cells in Excel from the datagrid?
Instead of populating it cell by cell.
Thank you.
|
|
|
|
|
try here
http://www.xtremevbtalk.com/
They have a stronger Excel group there. .NET stuff, you are way better here.
*****************
"We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
|
|
|
|
|
hi all,
In our Application ,we have to use 175 SQL Functions.So there are many dependancies between each other.
That mean ,If we creating a function,we have to use several function to create it.
So I need to create a function relation ship between each other.(like relatinship between Tables)
Is there a way to get dependancies and relation in functions?
thanks in advance.
|
|
|
|