|
Yup, I had this one, but the result was quit strange, because the context appeared around as far from the cursor as the cursor was located rom the upper left corner of my application window! Meaning the upper left corner of the context was twice the distance of the mouse distance of the left corner of the application.
Do you have an idea why?
Because I also tried Control.MousePosition.
Same result!
Because I can't find out why!
And a second question: When selecting one of the MenuItems I do want the selected one to being placed in the TextBox the Context "belongs" to. But to do so, I do have to create an eventhandler for the clickevent, but then I do loose access to my TextBox.
Well it looks like this:
....
System.Windows.Forms.ContextMenu ctNameKeyMenu;
ctNameKeyMenu = new System.Windows.Forms.ContextMenu();
System.Windows.Forms.MenuItem menuItem1;
menuItem1 = new System.Windows.Forms.MenuItem();
System.Windows.Forms.MenuItem menuItem2;
menuItem2=new System.Windows.Forms.MenuItem();
ctNameKeyMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {menuItem1, menuItem2});
menuItem1.Index=0;
menuItem1.Text=ltemparray[1].ToString();
menuItem1.Click += new System.EventHandler(this.menuItem1_Click();
menuItem2.Index=1;
menuItem2.Text=ltemparray[2].ToString();
menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
ctNameKeyMenu.Show(lTextBox, Control.MousePosition);
.....
// same for menuItem2
private void menuItem1_Click(object sender, System.EventArgs e)
{
// assign the selected item of the context to the TextBox
}
But in the Clickevent section my TextBox is no longer accessible. So how do I get it in there? The selected item is available in the sender object, but this doesn't really help much.
Thanks again!
Stephan.
|
|
|
|
|
If you would read the documentation for the Cursor.Position property in the .NET Framework SDK, you'd see that the coordinate it in screen coordinates, so you must call PointToClient on the Control for which you want to transform the coordinates (relative to the Control ), passing the Cursor.Position to get a Point relative to the control:
Point p = button1.PointToClient(Cursor.Position);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks the hint worked!
Well I read this section, but I didn't count my application to be the client to the screen! But looking at it now, it looks clear and I am wondering why I didn't realize it earlier!
So then I can switch my task towards the event which has to take place when selecting an item in the context, namely assining it to the TextBox.
Thanks again!
Stephan.
|
|
|
|
|
|
If you want the algorithms supported by the CryptoAPI, then you'll have to P/Invoke a lot of CryptoAPI function and define lots of structs and consts to do it; otherwise, you can build an MC++ assembly without going to all that work. Either way, CryptEnumProviders is what you want to call, but this only enumerates CSPs supported by the CryptoAPI - not by .NET (which only encapsulates the standard CSPs). In addition, CSPs can be added using the <cryptographySettings> element which isn't used by an IConfigurationSectionHandler (technicall, the IgnoreSectionHandler is configured for that section) that you can use to query what's been added. CSPs can also be used without being registered in this way, like a TwoFish implementation I saw some time back.
The point is that there is not a single way to get what CSPs are available.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I am using service written by somebody else. I want to do some modifications in that. When I did modifications, I am seeing that service is stopping immediately. Do any body this kind of exp?? I am not getting any compile time or run time errors...
What is the reason for this.
Regards,
Satya
|
|
|
|
|
Where is the application stopping? Have you tried setting break points? Are any errors being thrown?
|
|
|
|
|
Hey everyone. Thanks in advance for any help. I have a WIN32 application that I am having difficulties with.
I basically have an ADD button for which you are able to add checkboxes at runtime. Then, I also have a REMOVE button which removes any checkboxes that are checked when the button is pressed. My difficulty lies in how to reference the checkboxes because they are all created at runtime. Here is some of my code.
<br />
function (int currentnumber) {<br />
<tab>myCheckBox = new System.Windows.Forms.CheckBox();<br />
this.panel1.Controls.Add(myCheckBox);<br />
myCheckBox.Location = new System.Drawing.Point(this.Group_label.Left-30, ystarter+(currentNumber*distance));<br />
myCheckBox.Name = "checkBox"+currentNumber;<br />
Console.WriteLine(myCheckBox.Name);<br />
myCheckBox.Size = new System.Drawing.Size(16, 24);<br />
myCheckBox.TabIndex = 6;<br />
}<br />
<br />
private void Remove_Group_Click(object sender, System.EventArgs e) {<br />
for(int i=1;i<=totalGroups;i++) { <br />
if (checkBox"+i.Checked == true) {<br />
this.panel1.Controls.Remove(checkBox"+i);<br />
}<br />
}<br />
}<br />
My REMOVE button click handler does not work properly. I can't get it to compile because it says that checkBox+i is not a valid Checkbox.
How do I reference my checkboxes that were created at runtime whose names should be:
checkBox1,checkBox2,....
Thanks again for any help.
|
|
|
|
|
That's not a valid variable name. You must enumerate your Controls and find a CheckBox with that name:
private Control GetControl(string name, bool caseInsensitive)
{
if (name == null) throw new ArgumentNullException("name");
foreach (Control c in Controls)
if (string.Compare(name, c.Name, caseInsensitive) == 0) return c;
return null;
} This returns a reference to a Control , so you can use the is statement to easily determine if it's a checkbox, or just recode the sample above to enumerate all Control s but in the conditional additionally use is to check if it's a CheckBox . Don't change Control c to CheckBox c (or something) because any control that is not a CheckBox will not cast and an exception will be thrown when enumerating.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Can someone tell me what is wrong with this code.
I've got a couple of custom controls in a groupbox that i need to dispose. I tried the following foreach loop, but i get the error "Specified cast not valid".
foreach (WorkersCtrl c in groupBox.Controls)
{
c.dispose();
}
Thanks.
|
|
|
|
|
But that's very simple: at least one of the Control s in groupBox.Controls is not a WorkersCtrl .
The Controls collection holds Control s or derived classes, not limited to WorkersCtrl only.
If you really only want to call Dispose() then change WorkersCtrl c into Control c and you'll be fine.
mav
|
|
|
|
|
Thanks, it was pretty stupid of me. I've got it working now.
|
|
|
|
|
You must have a control inside the groupbox that is not of or inherit from WorkersCtl. You could try a couple of different things. You could either throw an if statement in there, to determine if the object is of type WorkersCtrl, and just use the object base class inside your for each decleration. Or...., you could change workersctrl to object, and set a debug statement within the foreach statement, outputing each objects .gettype().tostring() to determine which object is throwing the invalid cast error.
|
|
|
|
|
Hi all,
I have a problem concerning Crystal Report's performance on Win2000.
I use datasets to push data into my report, but the assignment of the datasource to the report and the the creation of the report take way too much time on some Win2000 systems.
Here are the two code snippets that take so much time:
report.SetDataSource(dataSet);
ReportForm reportForm = new ReportForm(report, m_ResourceManager);
reportForm.Show()
Some examples of the performance of this code:
On my Windows XP:
SetDataSource: 3 seconds
show report: 2 seconds
A colleague's Win 2000:
SetDataSource: 2 seconds
show report: 2 seconds
Another colleague's Win 2000:
SetDataSource: 105 seconds
show report: 391 seconds
My application runs fine on every Windows XP that I tested and it also runs fine on some Win2000 systems.
But unfortunately there are some Win2000 systems that have very bad performance running my app.
I have no clue what could be the reason for this.
For example:
The Win2000 system's load is at about zero percent, when it is waiting for the SetDataSource method to return.
How can this be?
Any help appreciated.
Best regards
Bernd R.
-------------------------------------------
The light at the end of the tunnel has been switched off temporarily due to budget problems...
|
|
|
|
|
While Crystal Reports is not the most stable product in the computing world, I doubt this is the cause of your problem. I'd check first the database connections and/or the ammount of data that is being trasnferred on the slow machines.
Yes, even I am blogging now!
|
|
|
|
|
Database connection shouldn't be the problem, because there is no database. I use datasets!
And the amount of data transferred is not very high.
I also don't think that the hardware is the problem, because we use computers with Pentium4 2,8GHz and 512 MB of RAM.
I guess this must be some weird configuration issue
-------------------------------------------
The light at the end of the tunnel has been switched off temporarily due to budget problems...
|
|
|
|
|
Hi,
I am using a Stored Procedure to validate Login Process:
Stored Procedure is defined as follows :
----------------------------------------------------------
CREATE PROCEDURE spCheckLogin
@LoginID char(20), @Pwd char(8), @Response int OUTPUT
AS
IF EXISTS (SELECT * FROM tEmployees WHERE LoginID=@LoginID AND Pwd=@Pwd)
Return 1
ELSE
Return 0
GO
----------------------------------------------------------
In C#, I am accessing this Stored Procedure as follows:
try
{
string temp="";
//open the connection
gvDatabase.scInventoryControl.Open();
//create the sql
sql = "spCheckLogin";
//create command
cmdLogin = new SqlCommand(sql,gvDatabase.scInventoryControl);
cmdLogin.CommandType=CommandType.StoredProcedure;
cmdLogin.Parameters.Add("@LoginID", SqlDbType.Char,20);
cmdLogin.Parameters["@LoginID"].Value=log;
cmdLogin.Parameters.Add("@Pwd", SqlDbType.Char,8);
cmdLogin.Parameters["@Pwd"].Value=p;
cmdLogin.Parameters.Add("@Response",SqlDbType.Int,4);
cmdLogin.Parameters["@Response"].Direction=ParameterDirection.Output;
Console.WriteLine("Data Access started");
cmdLogin.ExecuteNonQuery();
temp = cmdLogin.Parameters["@Response"].Value.ToString();
Console.WriteLine(temp);
//clean up code
cmdLogin.Dispose();
gvDatabase.scInventoryControl.Close();
Console.WriteLine("Data Access Closed");
}
catch(Exception ex) { Console.WriteLine(ex.ToString() ); }
------------------------------------------------------------
However It doesn't print any values, although I values do exists in the table
What am i doing wrong?
ThANX in ADvance
|
|
|
|
|
looks to me you got two thing mixed up.
you should eighter change youre sql code to
=======================
CREATE PROCEDURE spCheckLogin
@LoginID char(20), @Pwd char(8), @Response int OUTPUT
AS
IF EXISTS (SELECT * FROM tEmployees WHERE LoginID=@LoginID AND Pwd=@Pwd)
SET @Response=1
ELSE
SET @Response=0
GO
========================
OR you should use something like this in youre code:
========================
string temp="";
//create the sql
string sql = "spCheckLogin";
//create command
cmdLogin = new SqlCommand(sql,gvDatabase.scInventoryControl);
cmdLogin.CommandType=CommandType.StoredProcedure;
cmdLogin.Parameters.Add("@LoginID", SqlDbType.Char,20);
cmdLogin.Parameters["@LoginID"].Value=log;
cmdLogin.Parameters.Add("@Pwd", SqlDbType.Char,8);
cmdLogin.Parameters["@Pwd"].Value=p;
cmdLogin.Parameters.Add("@Response",SqlDbType.Int,4);
cmdLogin.Parameters["@Response"].Direction=ParameterDirection.Output;
Console.WriteLine("Data Access started");
try
{
//open the connection
gvDatabase.scInventoryControl.Open();
//use the connection
temp=(string)cmdLogin.ExecuteScaler();
Console.WriteLine(temp);
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString() );
}
finally
{
//clean up code
gvDatabase.scInventoryControl.Close();
Console.WriteLine("Data Access Closed");
}
cmdLogin.Dispose();
========================
i hope this helps.
(p.s. i did not test above code)
cookies are for eating, not for websites.
|
|
|
|
|
Try...
// Add the return value parameter
SqlParameter param = m_oCommand.Parameters.Add( "RETURN_VALUE", SqlDbType.Int );
param.Direction = ParameterDirection.ReturnValue;
D!shan
|
|
|
|
|
In namespace WindowsApplication1 I declare the richTextBox1 which I want to CALL FROM OTHER NAMESPACES MANY TIMES MAKING CHANGES that I want TO STAY. How I could make it for maximum performance ?
The first time I declared it as public static removing the keyword this in front of it.
But every time I was going to the Form1.cs[Design]* and I was making just a little change to the richTextBox1 the static was leaving and the this was appearing again.(Can I stop it happens?)
The second time I was passing the richTextBox1 as reference variable for many functions. But I think it is slow.(Is it realy slow?)
|
|
|
|
|
Your 'static' change is happening because the Windows Forms designer requires the controls on the form you're designing to be instance variables.
If you want, yes you can pass the rich text box into the functions you want to use it in. No, this is not slow, you're not copying the rich text box, just a small pointer to the rich text box.
A better solution is NOT to use static, and instead pass the rich text box once to the other class, then store that variable in the other class. For instance
class Form1
{
...
MyOtherClass theOtherOne = new MyOtherClass(this.richTextBox1);
}
class MyOtherClass
{
private RichTextBox theRichTextBox = null;
public MyOtherClass(RichTextBox rtb)
{
theRichTextBox = rtb;
}
void DoSomething()
{
theRichTextBox.Text = "hey I've modified it from another class";
}
}
#include "witty_sig.h"
|
|
|
|
|
Thank you very much Judah Himango !!!
|
|
|
|
|
Hi all
i need to programming a menu like Windows Start menu please can any one help me with example.
|
|
|
|
|
The simplest way is to add a Button to your container (like a Form or UserControl ) and a ContextMenu that is either defined with the MenuItem s you want, or adds them dynamically in the ContextMenu.Popup event handler. In the handler for the Button.Click event (inheritted from Control ), call ContextMenu.Show , passing the Button that was clicked and some Point , like the X and Y coordinates of the mouse position (remembering to transform the coordinates into client coordinates using Control.PointToClient ) or some corner of the Button (like new Point(0, 0) for the upper-left corner, since the coordinates are relative to the control you pass in the first parameter).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for your Reply
do you know menu in Visual Studio dot net in the left i named Docking Menu or striping menu .i need to do one like this . . .please help with example or ready made component
Thanks for your Time and help
Regards
Haytham
|
|
|
|