|
thanks for your feedback Sid. But I am still a bit confused. I was hoping you could give me another example bit simpler with code so that it can really sink in. Or even a link to a tutorial covers this topic.
thanks
|
|
|
|
|
This is how I would solve the problem. You still need to find a way to put your identifiers to some use.
I used this technique to load Plugins into a MenuItem and fire those events, with the user being able to freely change the item's menu position without having to re-assign events.
How that worked?
The user copies plugin dlls into the apps directory. each plugin has a GUID of some sort, which is used as the identifier on both the plugin and the item. This way, I can simply load the plugins up and let the user arrange them the way he needs them. I then simply look up the plugin via the identifier and let it do its stuff.
OK, some people will frown now. You are right, and it just occured to me as I read my explanation, that I am so freaking dumb.
This IS a solution to your described problem, but its totally crap for what I did. I was assuming that, as the Item Position changes when you modify MenuItem.Index, the associated handlers would somehow swich items. Bullshit. I never needed those, I just had to assing the plugin.dostuff to the appropiate MenuItem. NAAAAAAAAAAAAAAAAAARGH!
I guess I need more sleep
<br />
using System;<br />
using System.Drawing;<br />
using System.Windows.Forms;<br />
<br />
namespace contextdemo<br />
{<br />
public class MainForm : System.Windows.Forms.Form<br />
{<br />
private System.Windows.Forms.Panel panel1;<br />
private System.Windows.Forms.ContextMenu contextMenu1;<br />
private System.Windows.Forms.TextBox tbItems;<br />
private System.Windows.Forms.MenuItem menuItem1;<br />
private System.Windows.Forms.Button bCreate;<br />
public MainForm()<br />
{<br />
InitializeComponent();<br />
<br />
}<br />
<br />
[STAThread]<br />
public static void Main(string[] args)<br />
{<br />
Application.Run(new MainForm());<br />
}<br />
<br />
#region Windows Forms Designer generated code<br />
private void InitializeComponent() {<br />
this.bCreate = new System.Windows.Forms.Button();<br />
this.menuItem1 = new System.Windows.Forms.MenuItem();<br />
this.tbItems = new System.Windows.Forms.TextBox();<br />
this.contextMenu1 = new System.Windows.Forms.ContextMenu();<br />
this.panel1 = new System.Windows.Forms.Panel();<br />
this.SuspendLayout();<br />
this.bCreate.Location = new System.Drawing.Point(144, 160);<br />
this.bCreate.Name = "bCreate";<br />
this.bCreate.Size = new System.Drawing.Size(96, 24);<br />
this.bCreate.TabIndex = 2;<br />
this.bCreate.Text = "Create X Items";<br />
this.bCreate.Click += new System.EventHandler(this.BCreateClick);<br />
this.menuItem1.Index = 0;<br />
this.menuItem1.Text = "Standard Menu Item. Not generated.";<br />
this.menuItem1.Click += new System.EventHandler(this.standardMenuItem_Click);<br />
this.tbItems.Location = new System.Drawing.Point(32, 160);<br />
this.tbItems.Name = "tbItems";<br />
this.tbItems.Size = new System.Drawing.Size(88, 20);<br />
this.tbItems.TabIndex = 1;<br />
this.tbItems.Text = "5";<br />
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {<br />
this.menuItem1});<br />
this.panel1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));<br />
this.panel1.ContextMenu = this.contextMenu1;<br />
this.panel1.Location = new System.Drawing.Point(24, 32);<br />
this.panel1.Name = "panel1";<br />
this.panel1.Size = new System.Drawing.Size(144, 80);<br />
this.panel1.TabIndex = 0;<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(292, 237);<br />
this.Controls.Add(this.bCreate);<br />
this.Controls.Add(this.tbItems);<br />
this.Controls.Add(this.panel1);<br />
this.Name = "MainForm";<br />
this.Text = "MainForm";<br />
this.ResumeLayout(false);<br />
}<br />
#endregion<br />
void BCreateClick(object sender, System.EventArgs e)<br />
{<br />
int noOfItems = 0;<br />
try<br />
{<br />
noOfItems = Int32.Parse(tbItems.Text); <br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show("There was a problem. Creating 5 items instead.\r\n" + ex.Message);<br />
noOfItems = 5;<br />
}<br />
for (int i = 0; i < noOfItems; i++)<br />
{<br />
IndexedMenuItem itemToAdd = new IndexedMenuItem(i+1);<br />
itemToAdd.Click += new System.EventHandler(this.indexedMenuItem_Click);<br />
itemToAdd.Text = "Generated IndexedMenuItem No. " + (i + 1).ToString();<br />
contextMenu1.MenuItems.Add(itemToAdd);<br />
}<br />
MessageBox.Show("Items created");<br />
<br />
<br />
}<br />
<br />
void standardMenuItem_Click(object sender, System.EventArgs e)<br />
{<br />
MessageBox.Show("The standard MenuItem was clicked.");<br />
}<br />
void indexedMenuItem_Click(object sender, System.EventArgs e)<br />
{<br />
MessageBox.Show("A generated IndexedMenuItem was clicked. The item clicked had the identifier " + ((IndexedMenuItem)sender).Identifier.ToString());<br />
}<br />
<br />
}<br />
<br />
public class IndexedMenuItem : System.Windows.Forms.MenuItem<br />
{<br />
private int identifier;<br />
public int Identifier<br />
{<br />
get<br />
{<br />
return identifier;<br />
}<br />
}<br />
<br />
public IndexedMenuItem(int newIndex)<br />
{<br />
identifier = newIndex;<br />
}<br />
<br />
<br />
}<br />
}
Cheers
Sid
|
|
|
|
|
Im gonna do something very interesting tomorrow afternoon (I want to see if it works out). I dont want to go into any details, but that MAY be fun.
However, I am too tired. I came home late and tried to chop up a few lines to solve your problem.
That did not work out the way I thought it would. I did not reread your - or my - post, and simply assumed this was what you wanted. I read your startpost and my first reply and understood that I did not post what you or I wanted..
Shame on me. I need to get some sleep now, so try if you can use any of this code and come back tomorrow at the same time, I might have posted something useful by then.
Cheers
Sid
|
|
|
|
|
G'day Sid,
I think you have gone beyond the call of duty. Actually, you probably wont like to hear this but I came up with a novel solution myself. The night I had replied to your solution which i had found difficult to understand. Well the next morning I took another look at your difficult solution and an idea spawned which helped me overcome my problem. I couldnt believe it was so simple, so it looks like C# is slowly sinking into me .
I skimmed through your second solution and will go through it line by line once I get some sleep tonight.
Once again a million thanks for helping me out here. I truly appreciate it.
many thanks
Veeral
|
|
|
|
|
I have a problem in coding the code to compile and execute.I want to do an IDE eg. something like JCreator in Java that executes code and compiles it but its been giving me huge problems.Can you please help me!!
uni1985
|
|
|
|
|
First of all this forum handles C# problems, and second but not least : where is your problem??
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
This really isnt too difficult (if its all about a one-codefile project, that is):
Simply run some shell with "csc.exe codefile.cs" and pipe the output to a richTextBox or similar. then check if the new "codefile.exe" exists and spawn a shell with "codefile.exe".
That should do the job.
I just don't know how to create a shell under .NET
Cheers
Sid
|
|
|
|
|
Hi,
Guess this article will help you.
http://www.codeproject.com/csharp/matheval.asp
Thanks
SGS
|
|
|
|
|
hi..hi..hi
i want to aske you if you has information about (system class)in c#
and its used and how i can use it to do somthing like
shutdown and serial port.....
thank thank thke
ooosoooory the (thke) i mean thank............
|
|
|
|
|
I dont know a class in the FCL named System , but sure there is a namespace called System , if there is a class named system till us in which namespace this class exists , and lets discover together what this class can do ...
|
|
|
|
|
Hi, I think that he was mean system namespase because there is not systen class in .NET
|
|
|
|
|
Hello
I have a very difficult problem to explain. I have a password dialog box so that people can change there password. The dialog box will request for their current password, anc check that is is valid. Then request them to enter their new password and then re-enter their new password. The passwords are checked using the tab button when they leave a text box on the (leave event). When they have done all this they click the ok button and the new password is set. If however, they cancel using the cancel button. Then the dialog box will not close. This is the code below so you can better understand my problem.
This is the code for when the user enters the password, and presses the tab key to go to the next text box. When this event fires it will check the password is correct. Enter new password and re-enter password uses the same idea. I will not post it here as the code is the same.
<br />
private void txtEnterPassword_Leave(object sender, System.EventArgs e)<br />
{<br />
string queryValidatePwd = "SELECT Username, Password FROM AdminUsers WHERE Username = '" + lblLoginName.Text + "' AND Password = '" + txtEnterPassword.Text + "' ";<br />
<br />
try<br />
{<br />
OleDbCommand cmdValidatePwd = cnnChangePassword.CreateCommand();<br />
cmdValidatePwd.CommandType = CommandType.Text;<br />
cmdValidatePwd.CommandText = queryValidatePwd;<br />
<br />
OleDbDataAdapter daValidatePwd = new OleDbDataAdapter(cmdValidatePwd);<br />
DataTable dtValidatePwd = new DataTable("AdminUsers");<br />
<br />
int count = daValidatePwd.Fill(dtValidatePwd);<br />
if ( daValidatePwd.Fill(dtValidatePwd) == 1 )
{<br />
txtEnterNewPassword.Visible = true;<br />
txtEnterNewPassword.Focus();
}<br />
else<br />
{<br />
MessageBox.Show("Password is incorrect for this username - please try again","Incorrect Password",MessageBoxButtons.OK,MessageBoxIcon.Warning);<br />
txtEnterPassword.Clear();<br />
txtEnterPassword.Focus();<br />
}<br />
dtValidatePwd.Dispose();<br />
daValidatePwd.Dispose(); <br />
}<br />
catch ( OleDbException ex )<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
catch ( Exception ex )<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
}<br />
Code for when the user closes the dialog box. The the other textboxes have focus you cannot close this form. I have tired using this.close() as well, but still does not work.
<br />
private void btnCancel_Click(object sender, System.EventArgs e)<br />
{<br />
this.Dispose();<br />
}<br />
Thanks for you help in advance,
Steve
|
|
|
|
|
Your code looks fine to me, perhaps you should use the Close procedure to close your window. You say that the windows doesn't close so as odd as this may sound, but you should check all the events you handle, maby one of them is stopping you from closing your form.
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
In Click event handler for your Cancel Button , if you showed the form with ShowDialog (a modal dialog), try:
DialogResult = DialogResult.Cancel That should work.
Otherwise, call Hide if you created a modeless dialog (Form.Show ).
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Did you try setting the CancelButton property on the form to your Cancel button?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
HI,
how to use win32 datatype in c#.NET
am using
[DllImport("Kernel32", CharSet=CharSet.Auto)]
private unsafe static extern UInt32 CreateIoCompletionPort(UInt32 hFile, UInt32 hExistingCompletionPort, UInt32* puiCompletionKey, UInt32 uiNumberOfConcurrentThreads);
this function , n i wants to pass a socket to ist parameter as a handle
and when i convert socket to UInt32 it gives me
INVALID CAST EXCEPTION
so how i pass socket to UInt32 hFile this argument.???
please help me ...........
Thanks
babur.saeed@gmail.com
its_me_babar@yahoo.com
Babar
|
|
|
|
|
Handle dataTypes in C# must be IntPtr, therefor you procedure should look like this :
[DllImport("Kernel32")]
private static extern IntPtr CreateIoCompletionPort(IntPtr hFile, IntPtr hExistingCompletionPort, IntPtr puiCompletionKey, IntPtr uiNumberOfConcurrentThreads);
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
Thank u very much i have solved the problem,,,,,,,,
but now stuck into another problem
can u help me if i send u code?
|
|
|
|
|
|
Hi,
when i create a software with c# for different OS, do i need to compile the source code on every computers with destination OS, i mean, i create a project on winxp, but i wont that is runnable on windows2000 to, do i must to compile the project on win2000 first befor a create a release? I hope that my question is understandable!
thanx
mirsad
|
|
|
|
|
Hi!
No, you don't have to compile for every OS.
There are, however, some classes in the .NET framework that are not supported on every OS .NET runs on (for example, a FileSystemWatcher only is available on NT-based systems: NT, 2000, XP, 2003).
The framework documentation tells you which OS's a class is supported on.
mav
|
|
|
|
|
No.
Just like Java, C#/.NET-FW means: compile once, run anywhere.
There are, however, a few drawbacks:
In order to run an application on a target system, the target system must have a .NET-Framework installed.
There also IS a difference between v1.0 and v1.1 Applications (i.e. Applications for the .NET-FW Version 1.0 and .NET-FW Version 1.1), so take that into consideration.
AFAIR, there is no .NET FW available for Win95, which might or might not be a problem.
Last drawback: The Microsoft .NET Framework is only available for "Wintel", AFAIK. You might have to use MONO as the executing framework instead, which is available at www.go-mono.com (read the corresponding article here on CP).
That should have been all
Cheers
Sid
|
|
|
|
|
good answer.
If you copied that response to notepad, you could use it 100+ times a day on these forums.
|
|
|
|
|
heh, actually I was thinking aboout kind of browser plugin... like code snippets in VS.NET 2k5, but with common links to MSDN, Colin's SQL Injection article etc. You know, things you keep writing again and again. Unfortunately I don't know how to do IE/FF plugin and I don't have much time to learn...
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
hi,
thanx to all for answers, i create nice tool with c#(with help of course), but they dont work on win2000, on WinXP is no problems! That is the problem what i have, and i am beginner in this, the error message is when i start this tool after installation on Win2000 follow:
Enable JIT-Debugging in the section: system.windows.forms !
This is a ATL tool with hook's, and inplemented a cmd.exe in the Window Explorer if you want, for example, you dont need to start the console explicit, only press a key, example alt + m !
But thanx for help
mirsad
|
|
|
|
|