|
Here's code snippet that shows different context menus for selected tree node.
private void Form1_Load(object sender, System.EventArgs e)
{
// create the root node
TreeNode treeNodeRoot = new TreeNode("Root");
treeNodeRoot.Tag = "root";
// create first child node
TreeNode treeNodeChild1 = new TreeNode("Child1");
treeNodeChild1.Tag = "child";
treeNodeRoot.Nodes.Add( treeNodeChild1 );
// create second child node
TreeNode treeNodeChild2 = new TreeNode("Child2");
treeNodeChild2.Tag = "child";
treeNodeRoot.Nodes.Add( treeNodeChild2 );
treeView1.Nodes.Add( treeNodeRoot );
}
///
/// Create context menu
///
/// <param name="tag" />tag value
/// <returns>
private ContextMenu GetContextMenuByTag(string tag)
{
ContextMenu contextMenu = new ContextMenu();
if( tag.StartsWith("child") )
{
contextMenu.MenuItems.Add("Child menu item");
}
else
{
contextMenu.MenuItems.Add("Root menu item");
}
return contextMenu;
}
private void treeView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button==MouseButtons.Right)
{
// retrive node or use treeView1.SelectedNode
TreeNode theNode= treeView1.GetNodeAt(e.X, e.Y);
if (theNode!=null)
{
if( theNode.Tag!=null )
{
ContextMenu contextMenu =
GetContextMenuByTag((string)theNode.Tag);
contextMenu.Show( treeView1, new Point(e.X, e.Y) );
}
}
}
}
DevIntelligence.com - My blog for .Net Developers
-- modified at 3:16 Monday 9th January, 2006
|
|
|
|
|
Subscribe to the MouseDown event of the Treeview control. In the event handler, code it like
if (e.Button == MouseButtons.Right)
{
Point point = new Point(e.X, e.Y);
TreeNode node = treeView.GetNodeAt(point);
if (node == null)
return;
treeView.SelectedNode = node;
if (node.Tag is TypeX)
{
XContextMenu.Show(treeView, point);
}
else if (node.Tag is TypeY)
{
YContextMenu.Show(treeView, point);
}
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thx I didn`t knew about the treeView1.GetNodeAt method
|
|
|
|
|
Dear all,
I have developed a .NET dll. I wants to use this dll in Win32(Delphi) applications. Is it possible to do the same.
The data type of arguments passed to the functions in the dll & returned from it are compatible. The return type is a byte array & the arguments passed are string. But, when i used this dll in a Win32 application(developed using Delphi), EAccessViolation exception occurs.
Can anyone suggest me how to use the .net dll in win32 applications?
Thanks & regards,
Abhilash
|
|
|
|
|
|
Clickety Cops[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Delphi is COM based, so you have to write your .DLL to expose its properties and methods to COM. You can find documentation on what you need to do here[^].
For a bit more friendly discussion, see the link the other poster gave you.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 9:23 Monday 9th January, 2006
|
|
|
|
|
i tried creating the tlb of the dll. The is created, But again the application gives the same exception. Whether we have to include this tlb also in the delphi(pascal) application? How can i acheieve that. At present i am declaring the functions in the dll in application & using it.
Also, when we deploy the application & install it in a target PC, whether it will take care of the registration of the dll in the target PC also. Means, when we run the setup of the application, it must handle all the issues.
If i go for a COM+ component, whether i can achieve the same?
Thanks & Regards,
Abhilash
|
|
|
|
|
i have no idea why that exception is being thrown. There's only about a thousand different causes. Try posting the code where the Exception is thrown.
You have to take care of building a Setup project for your application, including any .DLL's it uses and their registration. Since your using a C# class library in your Delphi app, you also have to make sure that the .NET Framework is installed so the .DLL can be loaded and used.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi, is there a way to run other applications within my application? For example, run Internet Explorer and Firefox in my application in separate tabs.
Thank you.
KiT
|
|
|
|
|
You can't run the acutal applications and expect them to render their windows inside your application.
You could get away with something similar by putting a WebBrowser control of your tabpage. IE supplies a COM component that can be used. I don't know about Firefox.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi all,
Listen i got a problem and i don't know it's cause. when i run that piece of code:
grf = Graphics.FromImage(metafile);
//do what ever i want with grf
grf.Dispose();
grf = Graphics.FromImage(metafile);
i got an out of memory exception.
i realized that if i created a graphic object twice from metafile i got that exception.by the way when i use normal image not metafile it works. i wanna know why that with metafiles?
marcoryos
|
|
|
|
|
|
I'm not sure how to solve this problem and I'm hoping someone can help. I'm writing an application that allows the user to configure logical operations using IF,THEN,AND,OR operators, but I'm a bit confused as to the best way to evaluate the conditional statement once it is built. For examples lets say that the user specifies a three part conditional statement and I have evaluated each part and stored the correct boolean value in an ArrayList. How do I evaluate all the parts of the condition at once ?
ArrayList Parts = new ArrayList();
Parts.Add(false);
Parts.Add(false);
Parts.Add(true);
bool Result=false;
for(int x=0;x<Parts.Count;x++)
{
bool Part = (bool)Parts[x];
if(x==0)
Result=Part;
else
{
Result=Result || Part;
if(!Result)
break;
}
}
Debug.WriteLine(Result.ToString());
If I evaluate the array in groups of two, the condition is incorrectly false when comparing the first two values (false || false).
What's the best way to evaluate user defined conditional statements ?
Remeber there can be X number of conditionals and both the || and && logical operators can be used.
Thanks for taking the time to read this lengthy message....
|
|
|
|
|
Okay - so you've parsed the user input and you have a bunch of expressions which evaluate to a boolean and the logical operators. What I've done in the past is create a class that represents a filter. A filter can be any sequence of conditional statements. The Filter class has three derived classes. AndFilter, OrFilter and BooleanFilter. The base class Filter looks like this:
public abstract class Filter
{
public abstract bool Evalutate();
}
The concrete classes override Evaluate are
BooleanFilter - this is a simple one. Its job is just to return the boolean value it was created with. This is what you create for each conditional statement (I'll show you how to plug it all together in a moment):
public class BooleanFilter : Filter
{
private bool value;
public BooleanFilter(bool value)
{
this.value = value;
}
public override bool Evaluate()
{
return value;
}
}
Then there is the AndFilter (the OrFilter class is almost identical so I'll not show it). The job of this class is to determine if the Evaluation of Filter A && Filter B
public class AndFilter : Filter
{
private Filter filterA;
private Filter filterB;
public AndFilter(Filter filterA, Filter filterB)
{
this.filterA = filterA;
this.filterB = filterB;
}
public override bool Evaluate()
{
bool result = filterA.Evaluate() & filterB.Evaluate();
return result;
}
}
Okay - So we have our filter classes now. All we need to do is to chain them up. Now, you have probably realised we are still evaluating in groups of two, but where this differs from your design is that this will evaluate a tree structure, not a sequential structure. Always you are comparing the nodes on the left to the nodes on the right. Some example code:
BooleanFilter a = new BooleanFilter(false);
BooleanFilter b = new BooleanFilter(false);
BooleanFilter c = new BooleanFilter(true);
BooleanFilter d = new BooleanFilter(true);
AndFilter andAB = new AndFilter(a, b);
AndFilter andBC = new AndFilter(b, c);
OrFilter orBC = new OrFilter(b, c);
Filter aOrBOrC = OrFilter(a, orBC);
Filter aAndBOrC = AndFilter(a, orBC);
Does this help?
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
-- modified at 20:28 Sunday 8th January, 2006
|
|
|
|
|
I figured it out. I actually had the right solution the whole time, I just needed to let the loop run its course instead of using the break command when it equated to false. Dumb....very dumb.
|
|
|
|
|
i want to get the X, Y mouse position respect the monitor screen.
how?
|
|
|
|
|
ok i've solved with System.Windows.Forms.Form.MousePosition.X and .Y
|
|
|
|
|
Or you can use Control.MousePosition.X and Y
|
|
|
|
|
Hello all,
I have created a dialog (with alot of buttons and checkboxes), and I want this dialog to act like a message box:
I have a class, lets call it DialogBox, which has a method showInfo() which returns int type value. The method shows the dialog and return the value based on the users choice. The problem is: I want to do a loop that waits for the user choice.
I hope that my problem is clear!
cheers!
tmp0
|
|
|
|
|
No, I have no idea what you want. ShowDialog will make your dialog instance act like a message box. If you want to keep showing the dialog over and over until the input is acceptable, this is bad UI, your dialog should not close until it has the input it needs, and it should tell the user why it refuses to close, or better yet, don't make the OK button clickable until validation succeeds.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hello Christian!
Sorry if it was a silly question; I should have simply said that I want a modal dialog (not a modeless dialog), which describes my problem more clearly.
Anyway, ShowDialog() did solve my problem! Thank you!
tmp0
|
|
|
|
|
Anyone know of a lossless jpg library in C# ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Depends if you want it free or not.
Atalasoft DotImage[^] does lossless JPEG.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
$1000 for an SDK that gives us lossless jpg is not unreasonable, but I'm not the one paying, and the one paying has decreed - find something free. Especially when this is overall an imaging SDK, and my core function is to write imaging code...
Christian Graus - Microsoft MVP - C++
|
|
|
|