|
Here is a code example of what I want to do.
<br />
private void AdminTree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)<br />
{ <br />
this.DisplayProperties( e.Node );<br />
}<br />
<br />
private void DisplayProperties( object inNode )<br />
{<br />
}<br />
<br />
private void DisplayProperties( QuestionNode inNode )<br />
{<br />
this.PropertiesGroupBox.Controls.Clear();<br />
<br />
this.QuestionPropertiesControl.QuestionText.Text = inNode.QuestionData.Question;<br />
this.QuestionPropertiesControl.AnswserType.Text = inNode.QuestionData.CatalogAnswerType.AnswerTypeName;<br />
this.QuestionPropertiesControl.Status.Text = inNode.QuestionData.Status;<br />
this.QuestionPropertiesControl.Dock = System.Windows.Forms.DockStyle.Fill;<br />
<br />
this.PropertiesGroupBox.Controls.Add( this.QuestionPropertiesControl ); <br />
}<br />
<br />
private void DisplayProperties( CatalogNode inNode )<br />
{<br />
this.PropertiesGroupBox.Controls.Clear();<br />
<br />
this.CatalogPropertiesControl.CatalogName.Text = inNode.CatalogData.Name;<br />
this.CatalogPropertiesControl.DisplayText.Text = inNode.CatalogData.ViewName;<br />
this.CatalogPropertiesControl.Status.Text = inNode.CatalogData.Status;<br />
this.CatalogPropertiesControl.Dock = System.Windows.Forms.DockStyle.Fill;<br />
<br />
this.PropertiesGroupBox.Controls.Add( this.CatalogPropertiesControl ); <br />
<br />
}<br />
I currently have AdminTree_AfterSelect written as follows. It works but I was wondering if anyone had any ideas on a cleaner way of doing it.
<br />
private void AdminTree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)<br />
{ <br />
if( e.Node is QuestionNode )<br />
{<br />
this.DisplayProperties( e.Node as QuestionNode );<br />
}<br />
else if( e.Node is CatalogNode )<br />
{<br />
this.DisplayProperties( e.Node as CatalogNode );<br />
}<br />
}<br />
Thanks in advance!
|
|
|
|
|
Even though TreeViewEventArgs.Node is of Type TreeNode , the actual object is of Type QuestionNode or CatalogNode so you don't need to cast it like you're doing. For instance, even though the GetType method is inherited form Object , it will always return the Type of the actual object. I even have something similar to what you have with a massive amount of tree nodes that even have other base classes and you don't need to cast them (either using the cast operator or the as keyword). So, when you call DisplayProperties with simply e.Node , it will automatically pick the correct one because the Type is either the QuestionNode or the CatalogNode , despite the Type that TreeViewEventArgs.Node is defined as (as long as its a base class).
For example:
using System;
public class Test
{
public static void Main()
{
DisplayText(new A1());
DisplayText(new A2());
}
private static void DisplayText(A1 a)
{
Console.WriteLine("DisplayText (1): {0}", a.Text);
}
private static void DisplayText(A2 a)
{
Console.WriteLine("DisplayText (2): {0}", a.Text);
}
}
public class A
{
public virtual string Text
{
get { return "A"; }
}
}
public class A1 : A
{
public override string Text
{
get { return "A1"; }
}
}
public class A2 : A
{
public override string Text
{
get { return "A2"; }
}
} The output would be:
DisplayText (1): A1
DisplayText (2): A2
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
You are correct, but in terms of a treeview and or any of the event driven systems not quite.
Take a look at the following event handler
<br />
private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)<br />
{<br />
this.DisplayType( e.Node ); <br />
}<br />
You are passed the node from e (e.Node) and it is of type TreeNode. If you call e.Node.GetType() you will get the correct type but when used in the following context it is simply a TreeNode the base class. See method DisplayType() methods and the treeView1_AfterSelect() method.
Copy/Paste and run the following example and you will see what I mean.
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace test<br />
{<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
private System.Windows.Forms.TreeView treeView1;<br />
private System.ComponentModel.Container components = null;<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
<br />
<br />
TreeNodeType1 tnt1 = new TreeNodeType1();<br />
tnt1.Text = "Type 1";<br />
<br />
TreeNodeType2 tnt2 = new TreeNodeType2();<br />
tnt2.Text = "Type 2";<br />
<br />
this.treeView1.Nodes[0].Nodes.Add( tnt1 );<br />
this.treeView1.Nodes[0].Nodes.Add( tnt2 );<br />
<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
#region Windows Form Designer generated code<br />
private void InitializeComponent()<br />
{<br />
this.treeView1 = new System.Windows.Forms.TreeView();<br />
this.SuspendLayout();<br />
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;<br />
this.treeView1.ImageIndex = -1;<br />
this.treeView1.Location = new System.Drawing.Point(0, 0);<br />
this.treeView1.Name = "treeView1";<br />
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {<br />
new System.Windows.Forms.TreeNode("Root Node")});<br />
this.treeView1.SelectedImageIndex = -1;<br />
this.treeView1.Size = new System.Drawing.Size(412, 393);<br />
this.treeView1.TabIndex = 0;<br />
this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(412, 393);<br />
this.Controls.Add(this.treeView1);<br />
this.Name = "Form1";<br />
this.Text = "Form1";<br />
this.ResumeLayout(false);<br />
<br />
}<br />
#endregion<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new Form1());<br />
}<br />
<br />
private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)<br />
{<br />
this.DisplayType( e.Node ); <br />
}<br />
<br />
private void DisplayType( object inNode )<br />
{<br />
MessageBox.Show(<br />
"Caught an Object",<br />
"Name Entry Error",<br />
MessageBoxButtons.OK,<br />
MessageBoxIcon.Exclamation );<br />
}<br />
<br />
private void DisplayType( TreeNodeType1 inNode )<br />
{<br />
MessageBox.Show(<br />
"Caught a TreeNode1",<br />
"Name Entry Error",<br />
MessageBoxButtons.OK,<br />
MessageBoxIcon.Exclamation );<br />
}<br />
<br />
private void DisplayType( TreeNodeType2 inNode )<br />
{<br />
MessageBox.Show(<br />
"Caught a TreeNode2",<br />
"Name Entry Error",<br />
MessageBoxButtons.OK,<br />
MessageBoxIcon.Exclamation );<br />
}<br />
}<br />
<br />
public class TreeNodeType1 : System.Windows.Forms.TreeNode<br />
{<br />
public TreeNodeType1()<br />
{<br />
}<br />
}<br />
<br />
public class TreeNodeType2 : System.Windows.Forms.TreeNode<br />
{<br />
public TreeNodeType2()<br />
{<br />
}<br />
}<br />
}<br />
<br />
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Scott Barr
Senior Software Engineer
scott@thorin.ca
http://www.thorin.ca
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
You're right - I constructed a bad example app that wasn't taking into account the right conditions. In this case, your original code was just fine and obviously necessary.
In the future, though, please use the <pre></pre> tags for code - it's much more readable - and specify the output condition as I did above. It certainly helps expedite the process.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Saw the <code> tag and didn't even notice the <pre> tag. Will use from now on! Thanks!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Scott Barr
Senior Software Engineer
scott@thorin.ca
http://www.thorin.ca
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
|
|
|
Hi guys,
Im trying to convert some visual basic code into c#, dose anybody know what's the equal things in c# for following function declaration and type.
any help is appreciated.
Public Declare Function Test Lib "x.dll" _
Alias "#3" (ByVal F1 As String, ByVal F2 As Long, ByVal F3 As Long, CDCAr As CDCAResult) As Long
Type CDCAResult
ID_0 As Byte
ID_1 As String * 17
ID_2(0 To 11) As Long
ID_3(0 To 7) As String * 41
End Type
|
|
|
|
|
For information on P/Invoking native functions, see the DllImportAttribute documentation in the .NET Framework SDK. An example follows:
[DllImport("x.dll")]
private static extern long Test(
string f1, long f2, long f3, CDCAResult CDCAr); For the struct, you create the managed version just like you would re-create it in VB:
[StructLayout(LayoutKind.Sequential)]
public struct CDCAResult
{
public byte id0;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=17)]public string id1;
public long id2;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=41)]public string id3;
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
thanx for reply,
I have 2 question:
1- Is it the same declaration for Fixed-Length String and arrays which contains Fixed-Length String for exapmle:
F1 As String * 31
F2(0 To 7) As String * 41
2- when i use like this
[DllImport("x.dll")]private static extern long Test( string f1, long f2, long f3, CDCAResult CDCAr);
i get error, but if i use by reference like this:
[DllImport("x.dll")]private static extern long Test( string f1, long f2, long f3, [MarshalAs(UnmanagedType.Struct)] ref CDCAResult CDCAr);
it works without error, but still dosen't return correct value for Fixed-Length String in that structure.
any help really appreciated.
best regards
|
|
|
|
|
Sorry, didn't notice that the last param in your Function was a ByRef. Yes, the ref keyword would be necessary then. You could also use the out keyword if you don't need to pass an initialized struct into the function. That would save you from having to instantiate the struct before calling the method.
As far as the fixed-length string question, you'll have to jog my memory on the F2(0 To 7) As String * 41 syntax. It's been a LONG time since I programmed in VB.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I also got to thinking that the encoding could be the problem. Does this function that you're wanting to P/Invoke only support ANSI characters, Unicode characters, or either ANSI or Unicode depending on the operating system? Depending on what encoding it uses, you should add the CharSet property in the StructLayoutAttribute :
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct CDCAResult
{
} The SizeConst property in the MarshalAsAttribute will make sure that the offsets are correct for the String fields, so assuming that the rest of your fields where the values you were expecting the character encoding is most likely the problem.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
you are right, encoding was problem, that unmanaged dll dose not support Unicode, when i use Ansi, every things gose through.
I really appriciate your help and knowledge.
|
|
|
|
|
I am looking for info on creating application switches. After creating a shortcut in the users Startup folder, I want to start the application minimized.
Can anyone pass me a heads up ?
Thanks in Advance
**DAN**
|
|
|
|
|
|
Actually, you don't even need to parse a command line to start your app in a minimized state. just don't hard-code the Form.WindowState property and in the shortcut properties for your application, set the Run: setting to Minimized. You can also set this in the shortcut properties for an installer such as Windows Installer.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Anyone know of any components for writing CD's or DVD's in C# ? I presume there's no API's to do it in the language itself... I've found the MSDN one that does them in XP, but I want to be able to create video CD's, which this will not do.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
|
Thanks - got that, but it doesn't do what I want. I edited my post to clarify, so I guess you didn't see it, but I added that what I want is to burn VCD's or movie DVD's.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I'd love to know exactly how DVD authoring works, but I don't think a lot of it is public information. I'd love to make a cheesy utility (cheesy in that it's not WYSIWYG GUI etc.) that took an XML file and created a proper DVD image.
If you find some good specs on DVD's let me know.
A decent place to start looking at all this stuff is doom 9.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Christian,
Your post got me searching after work. I've wanted some good DVD authoring libraries for a while, and like I said in my other post, I'd love to be able to make something that simply used XML as input and created a DVD. It turns out, someone else is many steps ahead of me.
I found a pretty cool project on SourceForge. Take a look at this project. They've basically created a console application (Win32/*nix) that takes an XML file as input and generates a DVD. It relies on other console apps (it's very *nixy like that), but it appears to actually get the job done.
It's not exactly a library, but the source code is available and the application in general seems very ripe for automating.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Cool - thank you.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
The VCD format allows one to place data on a disc without CRC checking thus u can fit a full 800mb on an 80min cd (like an audio cd). I have tried to make VCD's in the past, but with no luck though.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
So in other words, just duplicating the file format of VCDs and burning them won't work ? Damn.
I've made heaps of VCD's that worked fine, just not programatically.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Looking for some help on how to print a custome page size. What I have is a third party pdf creator which is set up as a print driver in which you select it just like a printer and then send it a print doc(document.print()).
The problem is that when you select the paper size it does not retain the selection and always goes back to the default size. From what I have read this is a know bug in .net and the only fix in win32 api's. I am not familiar with how to do win32 api call in .net and am looking for any help I might be able to get. Fairly new at this stuff so any code would help.
lostegg
|
|
|
|
|
We have discussed this here a LOT in the last week or so. Please search the comments for the discussion of custom page sizes.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi. I'm a relative newbie with C#...I have some custom controls that are snarfed code from a co-worker (the only other C# code in our workplace).
I have created a windows control library project, added the code to it, and compiled it to the dll. Now I have gone to the custom controls and added them to the pane by selecting the dll file. But when I try to drag the control on to the form it gives me an error:
An exception occured while trying to create an instance of CTSSExp.Controls.ExplorerControl. The exception was "null" is not a valid value for 'control.'".
CTSSExp.Controls is the namespace the control is in and ExplorerControl is the name of the control.
Any suggestions?
Thanks.
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|