|
Create a custom event delegate and event inside the control that your main form can use. When the in-control button is clicked have it check the custom event for registrars and fire it off it they exits. Examples: (I wrote this in the web browser, not a compiler so there may be a few compiler mistakes)
public delegate void OnClickStart(object,SystemEventArgs);
public event OnClickStart ClickStart;
private void button1_Clicked(object sender, SystemEventArgs e)
{
if(this.ClickStart != null)
{
this.ClickStart(sender,e);
}
}
Now in your main form use the code like such:
CustomControl cc = new CustomControl;
cc.ClickStart += new cc.OnClickStart(Mainform_ClickStart);
public void Mainform_ClickStart(object sender, SystemEventArgs e)
{
}
Try this out and let me know if you have any other questions.
-- modified at 11:41 Friday 7th October, 2005
|
|
|
|
|
That is awesome! thank you SO much!
Why cant my books explain that as simply as you have.
Thanks again for opening my eyes.
|
|
|
|
|
No problem, feel free to email me as well if you have any other c# questions
|
|
|
|
|
I'm not a dot net guru, but I had a similar issue and will share.
I created a control that creates a SQL statement based upon user selections. I needed an event that would fire when the SQL was generated. I first declared the following:
public delegate void SQLCreatedHandler();
[Category("Action")]
[Description("Fires when the SQL is created")]
public event SQLCreatedHandler SQLCreated;
When I wanted to fire the event I called this code:
//Raise event notifying subscribers that the SQL has been created
OnSQLCreated();
And the OnSQLCreated() method looked like this:
// If an event has no subscribers registerd, it will
// evaluate to null. The test checks that the value is not
// null, ensuring that there are subsribers before
// calling the event itself.
if (SQLCreated != null)
{
SQLCreated(); // Notify Subscribers
}
From the hosting application I created a handler for the event:
this.queryControl1.SQLCreated += new QueryControl.QueryControl.SQLCreatedHandler(this.queryControl1_SQLCreated);
And the method for the handler:
private void queryControl1_SQLCreated()
{
MessageBox.Show(this.queryControl1.SQL);
}
Hope this helps, don't mind the codeing. I found the articles here on CP that helped me create the above code. Search the articles, not messageboards
www.lovethosetrains.com
|
|
|
|
|
I'm having a bit of a problem getting this to work. I am writing an application that is using a StreamReader to read the output of a shell process. Here is the code to launch the process:
Process p = new Process();<br />
p.StartInfo.Arguments = "-n 1 -w 200 " + ip;<br />
p.StartInfo.FileName = "ping.exe";<br />
p.StartInfo.RedirectStandardOutput = true;<br />
p.StartInfo.UseShellExecute = false;<br />
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;<br />
p.Start();
The problem I'm having is that ProcessWindowStyle.Hidden seems to do nothing when UseShellExecute is = false. A (blank) console window still comes up for every IP address I'm trying to ping. Everything else works fine except the hiding of the window. I haven't been able to find anybody else that seems to be having this same issue out there. Any clues?
|
|
|
|
|
I used:
p.CreateNoWindow = true;
www.lovethosetrains.com
|
|
|
|
|
Excellent.. I feel so stupid now. Thanks for your response, worked like a charm.
|
|
|
|
|
Just glad that I can actually be of help.
www.lovethosetrains.com
|
|
|
|
|
I have a DLL written in C and am trying to access it with C#. I had to use DLLImport commands to talk with it and am having a problem. I get "Attemped to read or write protected memory." Now longs in C are 32 bits and longs in C# are 64. Could this be the problem and would just using a Convert.ToInt32(variable) fix it. I tried this when I made the call to the DLL and its still giving me the same error. Even when I declare my variable that I am sending to the DLL function as an int it doesnt work.
-Cal
-- modified at 9:30 Friday 7th October, 2005
|
|
|
|
|
Without real code it's hard to tell whether your DllImport declarations are correct.
But no matter if your C function is using long , int or DWORD parameters, you'll have to declare them as int in C#, because all these values are 32 bit long.
long in C# is 64 bit, adequate for a C function parameter with type QWORD .
Regards,
mav
|
|
|
|
|
C:
typedef void (WINAPI* TDM3TOOLKITShowForm)(long Slot);
C#:
[DllImport("mydll.dll")]
public static extern void ShowForm(int Slot);
private void btnShowtest_Click(object sender, EventArgs e)
{
int Slot = 3;
try
{
ShowForm(Slot);
}
catch (Exception ex)
{
lstBox.Items.Add(ex.ToString());
}
}
here is the code with only names changed for anonymity.
the winapi* part dont make a difference I dont think because I have used other functions out of this DLL. The ones that give me a problem are ones that have longs in them.
-- modified at 10:59 Friday 7th October, 2005
|
|
|
|
|
|
Hi, and thanks for your interest. I have some databound textboxes that are grouped on a number of pages in a tabcontrol. I use a button to call up a dialog box to pull data from a lookup table to speed populating some of the textboxes on the tab control. Updates seem to work fine untill I add some additional code in the Update event to check for null conditions. Then it gets strange, after I fill the textboxes from the lookup dialog I have to click in one (doesn't seem to matter which) of the filled textboxes for the updated information to be posted to the database. I have no code associated with tabcontrol or textbox mouse events on the form.
Code To Open Dialog (Form1)========================================
private void btnLmoLookup_Click(object sender, System.EventArgs e)
{
Form2 LmoLookup = new Form2();
LmoLookup.StartPosition = FormStartPosition.CenterParent;
if( LmoLookup.ShowDialog() == DialogResult.OK )
{
txtBoxDocName.Text = LmoLookup.docFullName;
}
LmoLookup.Dispose();
}
Code To Declare Public Variable (Form2)==================================
public string docFullName
{
get{return this.dsExtPhysLookup1.Tables["tblExternalPhysicians"].Rows[this.listBox1.SelectedIndex]["docFullName"].ToString();}
}
Code To Perform Update (Form1)===========================================
if(this.txtBoxDocName.Text.Trim().Length == 0) {
this.dsPatientIndex1.Tables["tblPatientIndex"].Rows[this.BindingContext[dsPatientIndex1, "tblPatientIndex"].Position]["patientRefDName"] = DBNull.Value;
}
else
{
this.dsPatientIndex1.Tables["tblPatientIndex"].Rows[this.BindingContext[dsPatientIndex1, "tblPatientIndex"].Position]["patientRefDName"] = txtBoxDocName.Text.Trim();
}
this.BindingContext[this.dsPatientIndex1, "tblPatientIndex"].EndCurrentEdit();
this.sqlDataAdapter2.Update(this.dsPatientIndex1);
-- modified at 8:53 Friday 7th October, 2005
|
|
|
|
|
I am going to write an application that will be controlling hardware through two RS-232 ports. The code that drives each port will be doing the exact same thing, but the actions will be totally independent of one another. What I need to determine is how to make the code run simualtaneously for each COM port, but independent of the other. My plan is to have a GUI the has two frames on the screen. In the left frame will be the code that interfaces with port COM1 and in the right frame will be the code that interfaces with port COM2. These will be asynchronous events and will basically be running independent of one another except that a signle application will encapsulate all of th code.
Overall, the theory behind what I am doing is pretty easy and I have a lot of experience wirting drivers for hardware, but I need to have mulitple instances running simultaneously in a single application. That is the part I have no expeience and am stuggling with. Any advice, links to tutorials,code ex., etc would be a great help.
In a nut shell, I want to be able to take a single application to operate some hardware, then be able to run it two, there, four, even more times within the same application at the same time.
Terry Jones
|
|
|
|
|
Put the rs232 code into a thread, and run 2+ seperate instances of it.
|
|
|
|
|
You should use .NET 2.0, it already contains all the code for interfacing with COM ports. .NET 1.1 does not provide this.
|
|
|
|
|
Hi all,
I am a Beginner to c#.
I Need to convert array of byte data type to string. How to do this..
ex:
byte[] bytes = new byte[1000];
this bytes get filled up. Now I need to convert to string.
How to do this..
|
|
|
|
|
Hello
You use the next code:
byte[] bytes = new byte[] { 0x41, 0x42, 0x43, 0x44, 0x45 };
string str = System.Text.Encoding.ASCII.GetString( bytes );
System.Diagnostics.Debug.WriteLine( str );
With best regards,
Andrew Kirillov, MCP x 3
Prize winner, August 2005
|
|
|
|
|
hi Kirillov,
Thanks a lot..
Worked and my problem is solved..
Have a nice day..
Shiva P
|
|
|
|
|
Can somebody point me to LDAP code for authenticating a user through LDAP or active directory.
Thanks in Advance.
Ramendra Kotharkar
Ramendra K
|
|
|
|
|
DirectoryEntry entry = new DirectoryEntry("LDAP://testdomain/DC=testdomain", "testdomain/" + textUser.Text, textPassword.Text);<br />
<br />
Object obj = entry.NativeObject;<br />
DirectorySearcher search = new DirectorySearcher(entry);<br />
search.Filter = "(SAMAccountName=" + textUser.Text + ")";<br />
search.PropertiesToLoad.Add("cn");<br />
SearchResult result = search.FindOne();<br />
<br />
if (null == result)<br />
{<br />
.<br />
.<br />
.<br />
}
This only works with AD, by the way: if you find that works with LDAP, please let me know
|
|
|
|
|
Hi
"%FrameworkSDKDir%\bin\resgen.exe" "$(ProjectDir)UserMessages.txt" "$(ProjectDir)UserMessages.resources"
I have added the above line in my post build event. It throws up a post build error.
(A tool returned an error code from the build event).
When i run the above command (replacing Project dir with directory path) from .net command prompt it works fine and returns the following message.
Read in 2 resources from 'c:\TestProject\UserMessages.txt'
Writing resource file... Done.
Thanks in advance.
|
|
|
|
|
Is there any wndows api or hook by which i can get application wide events in a windows application?
Please help me guys, i am stuck in a project.
Thanks in advance.
|
|
|
|
|
|
Hi
I was wondering if anyone could offer some advice on authenticating a .NET application with LDAP. The code seems to work fine with AD, but fails with LDAP. Also, I have a Java App that can do this just fine, but somehow the solution with .NET eludes me!
(extract)
DirectoryEntry entry = new DirectoryEntry("LDAP://testdomain/DC=testdomain", "testdomain/testuser", textPassword.Text);<br />
<br />
Object obj = entry.NativeObject;<br />
DirectorySearcher search = new DirectorySearcher(entry);<br />
search.Filter = "(SAMAccountName=testuser)";<br />
search.PropertiesToLoad.Add("cn");<br />
SearchResult result = search.FindOne();<br />
<br />
if (null == result)<br />
{<br />
.<br />
.<br />
.<br />
}
The test PC runs on a Windows XP box with .NET Framework 1.1, and is bound to whichever server we're testing on at the time.
The authentication server is a Mac OS X 10.4 server running LDAPv3 (I believe built on OpenLDAP, and should be similar in every way).
Any suggestions?
(or anyone with a Linux OpenLDAP domain out there?)
|
|
|
|