|
what gets measured must be in between the first and second NextValue and must take sufficient
time so the counters actually get updated. Google "performance nextvalue" and everything
will be revealed. Google knows everything.
|
|
|
|
|
And the penny / dime / ringgit / zloty etc finally drops!
The values are specific to *my* instance of the performance counter. I thought they were all stored magically somewhere and we just hook into this central store of counters and pulled values at will. But they only actually 'count' when we have an instance of the PerformanceCounter....all makes perfect sense now.
Thanks!
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
Malcolm Smart wrote: penny / dime / ringgit / zloty
May I suggest You switch to Euros like the rest of us ?
|
|
|
|
|
Luc Pattyn wrote: Google knows everything.
Almost like the Jedi Archives in Star Wars
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
I prefer the Ancients in Stargate-1
|
|
|
|
|
Luc Pattyn wrote: I prefer the Ancients in Stargate-1
Oh yeah, they were good too
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
I have an application that loads an image (having the role of a background image) and next to it, in a panel to the right, there are loaded some more images, small ones, representing various objects - those images are loaded each in it's own panel (smaller panels that the one containing them all).
The main picture (the background) is loaded in a PictureBox and it is divided in some regions (I store the pairs of points that define each region in a text file)
The objects should allow to be dragged and dropped over the regions they belong to (at first, when the objects were uploaded, they were each associated to at least one of the regions, the regions being previously defined).
HERE IS MY PROBLEM:
I can't mannage to make the drag and drop operation work the way that i want!!!
My code looks something like this:
private void Panel_MouseDown(object sender, MouseEventArgs e)
{
isDragged = true;
clickX = e.X;
clickY = e.Y;
}
private void Panel_MouseUp(object sender, MouseEventArgs e)
{
isDragged = false;
}
private void Panel_MouseMove(object sender, MouseEventArgs e)
{
Panel p = (Panel)sender;
isDragged == true)
{
if(!pictureBox1.Controls.Contains(p))
{
this.pictureBox1.Controls.Add(p);
}
p.Left = e.X + p.Left - clickX;
p.Top = e.Y + p.Top - clickY;
}
}
This code allows the panel loaded with that object to move anywhere in the window! The issue is that the application is addressed to kindergarden children, so it should be safer to use: this is why I want to limit the movement of the "object-panel" within the PictureBox, so that it couldn't leave its margins!!!
How do I do that???
Do you have any idea how can I check if an "object-panel" is dragged in the right region? Do you know any posibility to determine if an object positioned at the coordinates (x, y) is included inside a certain region (defined through pairs of points as mentioned above)???
I could really use your help!!!
Good gives us the power of creating the future. Use this power with reason.
|
|
|
|
|
This might help. First thing I found on programmatically moving the mouse.
http://www.thescripts.com/forum/thread501540.html[^]
-- modified at 10:43 Friday 20th July, 2007
Using the link above, this is an example of how to trap the mouse in a PictureBox , which should be hard to change to only trap while dragging.
private bool trap = false;
private void pictureBox1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e) {
trap = true;
}
private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e) {
if (trap) {
if (e.X < pictureBox1.Left) {
mouse_event(MouseFlags.Move, 1, 0, 0, UIntPtr.Zero);
}
if (e.X > pictureBox1.Left + pictureBox1.Width) {
mouse_event(MouseFlags.Move, -1, 0, 0, UIntPtr.Zero);
}
if (e.Y < pictureBox1.Top) {
mouse_event(MouseFlags.Move, 0, 1, 0, UIntPtr.Zero);
}
if (e.Y > pictureBox1.Top + pictureBox1.Height) {
mouse_event(MouseFlags.Move, 0, -1, 0, UIntPtr.Zero);
}
}
}
const int MK_LBUTTON = 0x0001;
enum Messages {
WM_LBUTTONDOWN = 0x0201,
WM_LBUTTONUP = 0x0202
}
[Flags]
enum MouseFlags {
Move = 0x0001,
LeftDown = 0x0002,
LeftUp = 0x0004,
RightDown = 0x0008,
RightUp = 0x0010,
Absolute = 0x8000
}
[System.Runtime.InteropServices.DllImport("User32.dll")]
static extern int SendMessage(IntPtr hWnd, Messages uMsg,
int wParam, IntPtr lParam);
[System.Runtime.InteropServices.DllImport("User32.dll")]
static extern void mouse_event(MouseFlags dwFlags, int dx,
int dy, int dwData, UIntPtr
dwExtraInfo);
Hehe, don't forget about Alt+F4 if you run this.
|
|
|
|
|
I found this in a CP Article[^] that might be easier to use:
[System.Runtime.InteropServices.DllImport("user32")]
static extern int SetCursorPos(int x, int y);
|
|
|
|
|
How can i exit or not to continue
the execution of statements in a certain event or function?
Just like "Exit Sub" in Visual Basic...
|
|
|
|
|
return.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
hi,
try
return;
Waleed Eissa
|
|
|
|
|
I have a line in the menu bar that is:
this.MenuBarEdit = new System.Windows.Forms.MenuItem();
What I would like to do is something like this:
string mbitem = "MenuBarEdit";
this.mbitem = new System.Windows.Forms.MenuItem();
Is something like this possible where the value of a variable is used instead of MenuBarEdit?
-- modified at 9:15 Friday 20th July, 2007
|
|
|
|
|
KPThor wrote: Is something like this possible where the value of a variable is used instead of MenuBarEdit?
I don't see what you are trying to achieve?
KPThor wrote: string mbitem = MenuBarEdit;
this.mbitem = new System.Windows.Forms.MenuItem();
The second line is (EDIT: Actually both lines are) invalid because you cannot assign a MenuItem to a string .
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
I am trying to use the text value of a string so the menubar could be dynamically modified from a xml file when the program loads.
<?xml version="1.0" encoding="utf-8"?>
<Menu>
<MenuBar item="File">
<MenuItem item="Open" acion="call" />
<MenuItem item="New" action="sub">
<SubMenuItem item="File" acton="call" />
<SubMenuItem item="Folder" action="call" />
</MenuItem>
</MenuBar>
<MenuBar item="Edit">
<MenuItem item="Cut" action="call" />
<MenuItem item="Copy" action="call" />
<MenuItem item="Paste" action="call" />
</MenuBar>
</Menu>
When the parser reads the xml file and comes to <MenuBar item="File"> and <MenuBar item="Edit"> it can place those menu items in the menubar.
|
|
|
|
|
KPThor wrote: When the parser reads the xml file and comes to <menubar item="File"> and <menubar item="Edit"> it can place those menu items in the menubar.
Okay - but all you need to do for that is add the item to the Controls collection of the control that will be the parent (e.g. A form, or a MenuStrip). You don't have to store it anywhere else (unless you want to)
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
I use this code to read some records from a access database with contacts exported from Outlook.
I get an error when the content of a field in the db is NULL bc it cannot be converted to string.
How could I correct this and the convert a Null field in a " " string?
Thanks
static void Main()
{
Program instan = new Program();
instan.ReadContacts();
Console.Read();
}
public void ReadContacts()
{
try
{
OleDbDataReader reader = null;
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\\AGH\\epafes_outlook_2007.accdb;Persist Security Info=False");
string comStr = "SELECT FirstName, LastName, BusinessPhone FROM Contacts";
OleDbCommand cmd = new OleDbCommand(comStr, conn);
conn.Open();
reader = cmd.ExecuteReader();
int i=1;
while (reader.Read())
{
string FName = (string)reader["FirstName"];
string LName = (string)reader["LastName"];
string BPhone = (string)reader["BusinessPhone"];
Console.Write("{0,-4}", i);
Console.Write("{0,-13}", FName);
Console.Write("{0,-13}", LName);
Console.Write("{0}", BPhone);
Console.WriteLine();
i++;
}
Console.WriteLine("\nFinish");
conn.Close();
reader.Close();
}
catch (Exception e)
{
Console.Write(e);
}
}
|
|
|
|
|
string FName = string.Empty;
object temp = reader["FirstName"];
if (temp != DBNull.Value)
FName = (string)temp;
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
kallileo wrote: string FName = (string)reader["FirstName"];
string LName = (string)reader["LastName"];
string BPhone = (string)reader["BusinessPhone"];
If a column is nullable in the DB, you should check for nullity in your code. Unfortunately, it is not the same as .NET null . You have to do it this way:
<code>
if (reader.IsDBNull(reader.GetOrdinal("FirstName"))
{
FName = null;
}
else
{
FName = (string)reader["LastName"];
}<code>
-----
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
|
|
|
|
|
Le Centriste wrote: You have to
"have to" is a bit strong. You don't "have to" do it that way (although it is a reasonable way to check) as there are other reasonable alternatives.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Yes, you're right. Wrong choice of words. I should have said "Here is an example".
-----
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
|
|
|
|
|
I think I found it....and it seems to work. But I'm not realy sure if this is the right way to do it.
string FName = Convert.ToString(reader["FirstName"]);
string LName = Convert.ToString(reader["LastName"]);
string BPhone = Convert.ToString(reader["BusinessPhone"]);
Thanks
-- modified at 9:17 Friday 20th July, 2007
This also works:
string BPhone = reader["BusinessPhone"].ToString();
|
|
|
|
|
Curiously, if you look at what Convert.ToString actually does, it just boils down to the same as:
string FName = reader["FirstName"].ToString();
So, is DBNull.Value.ToString() the value that you really want back?
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
DBNull.Value.ToString() returns an empty string, so it boils down to be the same as the examples we give, I believe.
-----
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
|
|
|
|
|
Hi
Since string is a reference type you could also do it like this:
<br />
string FName = reader["FirstName"] as string;<br />
string LName = reader["LastName"] as string;<br />
string BPhone = reader["BusinessPhone"] as string;<br />
greets
M@u
|
|
|
|
|