|
Ok, I gotcha. What I'm still fuzzy on is how to actually implement this in a wise way. For example, here's my code (which doesn't completely work yet).
using System;
using System.Windows.Forms;
namespace Test
{
public class Pipe : Control
{
public Pipe(){
}
protected override void OnMouseDown(MouseEventArgs e)
{
MessageBox.Show("a mouse was clicked and my object knows it");
base.OnMouseDown(e);
}
}
}
How do I add this to a form so that when a mouse is pressed, it distributes the event to my control? I was using "this.Controls.Add(new Pipe())" in initializeComponent, but it doesn't seem to work. Can someone please explain if what I am doing is retarded? Keep in mind, I am going to be adding to this class, but I just want to understand how I can have my components know when they are being clicked on. Thanks!
|
|
|
|
|
I Create The Componet myself,
i want to create my favourite Pict in the ToolBox
i search the information about it, but is show me example
below this.
// C#
// Specifies the bitmap associated with the Button type.
[ToolboxBitmap(typeof(Button)]
class MyControl : UserControl
// Specifies a bitmap file.
[ToolboxBitmap(@"C:\myImage.bmp")]
class MyControl : UserControl
[ToolboxBitmap(typeof(Button), @"C:\myimage.bmp")]
class MyControl : UserControl
how can i change the the absolute address' Picture
it means the picture include in my compont prject
in my class it like
[ToolboxBitmap(typeof(Button), @"myimage.bmp")]
class MyControl : UserControl
but how can i do
meetweb
|
|
|
|
|
When you use just a Type (the first constructor in your snippet), an image is used that has the same namespace and name as your class, but with a .bmp extension. I.e., if your class is Example.Class , then the image to be used is Example.Class.bmp . This image must be an embedded resource.
The second constructor is the name of an embedded resource, so you must include any namespace and the name of the file, like Example.Class.bmp .
The third constructor uses the namespace of the Type you pass in the first parameter and adds the name that you pass with the third constructor. If the class is Example.Class and you pass "Toolbox.bmp" as the name, then the image used is Example.Toolbox.bmp .
In all three cases, the image must be an emdedded resource, not a file on the computer. So, add a bitmap to your project, right-click and select Properties, then change the build type to "Embedded Resource".
You can find more details about this in the documentation for the ToolboxBitmapAttribute class in the .NET Framework SDK.
-----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-----
|
|
|
|
|
Has anyody experience in working with FIX? I'd need some help with understanding some general concepts.
Please let me know if anybody can help me with this
|
|
|
|
|
I have created a report using crystal reports but everytime I run it I have to type in the sql password for the database Is there any way I can save this information in the application?
TIA
------------------
Oh My goodness
|
|
|
|
|
You can keep the password in the connection string:
Provider=...; User ID=user; Password=pwd; ... This isn't very secure, but then again nothing you can store in the assembly isn't because anyone can use ildasm.exe or a similar tool to see what you have in the application.
If you're using SQL Server, perhaps a better way is to use integrated authentication, or SSPI, by excluding the User ID and Password params of the connection string and instead using Integrated Security=SSPI . This will use the credentials of the current (or impersonated) user to attach to SQL Server. The server must be configured to support mixed mode authentication, though (both SQL Server and Integrated Windows authentication).
The best practice is to not store secret information in your app because it's never secret. If you aren't using SQL Server and want you connection to be more secure, rely on either the user specifying the connection string in your application (perhaps as an option) or use ODBC.NET and let them configure their own DSN.
So, as long as this connection string is used for the DB connection for the CR report, you shouldn't have to worry about a password prompt.
-----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-----
|
|
|
|
|
But where is the connection string located within crystal reports?
------------------
I'm naked under my clothes...
|
|
|
|
|
It's not in Crystal Reports, but required to get the data source. If you're using the CR designer, it may not give you this change and instead store it as part of the report definition. Instead, make this a two step process and bind your report to a DataSet , which you can get using a DataAdapter or something. This makes your reports a little more durable so you don't have to worry about recompiling just to change the connection string or anything like that.
To set the data source on the report, use ReportDocument.SetDataSource . When designing, there's an option to design the report bound to a strongly-typed DataSet .
-----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-----
|
|
|
|
|
Thx for the info that helps greatly, doing that also means I can use stored procedures
------------------
I'm naked under my clothes...
|
|
|
|
|
Why isn't this working ?
conn.Open();
cmd = new SqlCommand("SPSearchRmiInfoFirstname", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Firstname", "O");
dad = new SqlDataAdapter(cmd);
dad.Fill(cpData);
rp.Load("cp.rpt");
rp.SetDataSource(cpData);
cpv.ReportSource = rp;
It doesn't display any data, am I doing something wrong
------------------
I'm naked under my clothes...
|
|
|
|
|
NeverMind I found out the problem, here is the working code.
conn.Open();
cmd = new SqlCommand("SPSearchRmiInfoFirstname", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Firstname", "O");
dad = new SqlDataAdapter(cmd);
dad.Fill(cpData.Dataset);
rp.Load("cp.rpt");
rp.SetDataSource(cpData.Dataset);
cpv.ReportSource = rp;
I forgot to pass the info of the dataset LOL
------------------
I'm naked under my clothes...
|
|
|
|
|
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-----
|
|
|
|
|