|
In C# how do my app get true wen both mouse buttons are down?
|
|
|
|
|
The MouseEventArgs class has a property Button that will tell you that.
It's a [Flags] enumeration, so more than one value can be OR'ed to build the final value.
So your event handler would look somethng like this:
private void MyApp_MouseDown(object sender, MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left &&
(e.Button & MouseButtons.Right) == MouseButtons.Right)
{
MessageBox.Show("Both buttons down");
}
} Regards,
mav
|
|
|
|
|
no... this code does not work correctly .. like if i press both buttons at the same time nothing happen... like if you are playing minesweeper you press both buttons ... i have tried this code but it did not work for me ...
Is there any thing else that i can do
|
|
|
|
|
private bool leftButtonPressFlag = false;
private bool rightButtonPressFlag = false;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) leftButtonPressFlag = true;
if (e.Button == MouseButtons.Right) rightButtonPressFlag = true;
if (leftButtonPressFlag && rightButtonPressFlag)
{
Color swap = ForeColor;
ForeColor = BackColor;
BackColor = swap;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) leftButtonPressFlag = false;
if (e.Button == MouseButtons.Right) rightButtonPressFlag = false;
}
|
|
|
|
|
|
What you mean? I badly speak english.
|
|
|
|
|
|
You are mistaken. Need AND. This code works correctly.
It is possible to write so:
private bool buttonPressFlag = false;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (buttonPressFlag)
{
Color swap = ForeColor;
ForeColor = BackColor;
BackColor = swap;
}
if ((e.Button & MouseButtons.Left) == MouseButtons.Left ||
(e.Button & MouseButtons.Right) == MouseButtons.Right)
buttonPressFlag = true;
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left ||
(e.Button & MouseButtons.Right) == MouseButtons.Right)
buttonPressFlag = false;
}
PS: Excuse me. At first time I has not understood your answer.
|
|
|
|
|
Lets go back to your original code listing
private bool leftButtonPressFlag = false;
private bool rightButtonPressFlag = false;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) leftButtonPressFlag = true;
if (e.Button == MouseButtons.Right) rightButtonPressFlag = true;
if (leftButtonPressFlag && rightButtonPressFlag)
{
Color swap = ForeColor;
ForeColor = BackColor;
BackColor = swap;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) leftButtonPressFlag = false;
if (e.Button == MouseButtons.Right) rightButtonPressFlag = false;
}
The correct way will be as such:
if ((e.Button & MouseButtons.Left) != 0) leftButtonPressFlag = true;
if ((e.Button & MouseButtons.Right) != 0) rightButtonPressFlag = true;
if (leftButtonPressFlag && rightButtonPressFlag)
This is becos MouseButtons is a Flagged enum. Lets look at some real values now.
[Flags]
enum MouseButtons
{
Left = 0x 0010 0000,
....
Right = 0x 0020 0000,
....
}
Now the value of e.Buttons, if both buttons were pressed, would be 0x 0030 0000 (Left | Right), you should see now why your method will fail try to match either value, and hence will not work correctly. Note for single buttons your method will indeed work, but will fail matching combinations of buttons.
I hope you understand If not, read abit about the binary (not boolean) operators of AND, OR, XOR, 1's complement. The windows calculator can actually help alot here! I remember it took me a good few months to understand it fully.
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
I add a new listview to my main form to add images to a treeview, but what happend is i cant see any images on all my controls (that use diffrent imagelists in diffrent classes) and when i remove the new imagelist everything gets back to normal ,what am i doing wrong?
|
|
|
|
|
i found that there is no reason why we should use username and password parameter in DirectoryEntry constructor, but why do they provide it?
since it will always use the current windows account which run the program to authenticate against active directory, so that whatever username and password i specify in DirectoryEntry constructor is useless.
Am i right?
your info is highly appreciated.
Thanks
|
|
|
|
|
i get the answer, i was wrong
|
|
|
|
|
Hello:
I have the next C# code:
r = new StreamReader("300_46C_UST04.txt", System.Text.Encoding.UTF7)
l = r.ReadLine()
The input file has the next data:
123+ABC3210_áéíóúñÑ\/ÁÉÍ--
After reading the record, variable "l" has:
123?_áéíóúñÑ\/ÁÉÍ--
It ignored the +ABC3210!! UTF is the best option for special characters such as Ñ, ñ, etc., but when the string has the character "+" .... it is terrible.
What Am I doing bad? I tried all the possibilities (with unicode, ascii, UTF8) but I have different results. When I delete the second parameter, i.e. System.Text.Encoding.UTF7, I obtain the next result:
123+ABC3210_\/--
(special characters where ignored!!)
Really, I do not understand.
Please .... a help?
|
|
|
|
|
What encoding is the file actually in? Did you create it?
If the file is in a certain encoding, you can get strange results when you read it with other encodings. Things get really crazy when unicode is involved, because there is not a simple 1 byte = 1 character mapping, especially when dealing with "special characters.
my blog
|
|
|
|
|
Hello Steven:
Thanks for your attention.
The input file was generated using notepad and I do not know the encoding used. Where can I check that? in my W2K parameters?
I live in Bolivia, South America, where Ñ, ñ, á ... etc. are very common.
I am very concerned about this problem because, I made many, many programs that read .txt information to load to a database and I fear that many of this spanish characters were lost. My God ... I never imagine this kind of problem.
My head (and my ass) are involved!!
What do you think I can do?
Best regards
|
|
|
|
|
You could try using System.Text.Encoding.Default for reading the file.
Because this uses the current system code page you should be able to read in files that have been written by other applications that are not concerned about encoding.
Regards,
mav
|
|
|
|
|
Notepad saves in ASCII.
/\ |_ E X E GG
|
|
|
|
|
Hi!
I am trying to load an image file, modify it (i.e. draw something into it for example) and save it again. I am so far:
Image img = Image.FromFile("test.jpg");<br />
Graphics g = Graphics.FromImage(img);<br />
g.DrawLine(System.Drawing.Pens.Black, 10, 10, 20, 20);
And now???? Now I have the thing in g (hopefully...). How do I get an Image of the Graphics object to save it using the Save method of Image? Or any other way to save it?? Or am I totally wrong? Some totally different method to accomplish the whole thing?
Thanks in advance and best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
You can just do img.Save("test.jpg", ImageFormat.Jpg)
and it will save the image.
When you draw using Graphics that was created from image, all the drawing is happening on the image surface, so if you save the image, all drawing will be kept.
|
|
|
|
|
Hello -
I have been working on a Windows App with three tabs in it (using the tabControl control). I have placed between 15 and 20 objects on each tab (labels, buttons, dropdowns, etc.) and made all of the backrounds transparent. Then I put a different image as the background of each tab, which creates this sort of watermark effect, which I really like. Unfortunately, when you swtich back and forth between the tabs in the .exe, it takes a few seconds each time to redraw all of the GUI objects, which looks pretty bad.
Does anyone have a solution for this problem? A way to draw the tab completely before displaying it? Background image as a GDI+ object? Double buffering?
Thanks,
jdrudolp
|
|
|
|
|
I've got a plugin arcitecture system that calls LoadFrom to load the .dlls in a specific folder and it works fine and dandy, imports everything, my code can create objects from types found in the loaded .dlls
HOWEVER, One issue i've not been able to solve is that, in some of the classes, I've got custom Type Editors for some of the classes in the "plugged in" .dlls
Whenever I set a created object from one of the plugged in .dlls and set it to a property grid's selected object, trying to edit it does not produce the correct type editor. This is especially the case with my custom collection classes. Since most of them are inherited from ArrayList, I constantly get the Object editor form.
Now here's the really wicked twist. If the plugins are set to references in my project in vs.net, The correct editors will appear just fine.
I did some debugging by getting a type for one of my collections that uses a custom editor, and wrote all the attributes from GetCustomAttributes method and the System.ComponentModel.EditorAttribute was still a recognized attribute on the class, eliminating my thought that perhaps the attribute was being lost during the LoadFrom.
I am totally baffled.
|
|
|
|
|
Totally a shot in the dark, but it seems like VS can't find the supporting dll's unless, as you said, you reference them.
Awful as it sounds, try putting your assemblies in the GAC. As I said though, this is a shot in the dark.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
Hunt The Wumpus
RealDevs.Net
|
|
|
|
|
I'm getting "System.OutOfMemoryException" in a block of code that has not changed in quite a while. Actually it is an instantiation of a User Control. There are a series of 4 UC's instantiated. The first one has had changes made to it. The remaining have not. If I comment out the second one, the error goes away.
The problem is that the error doesn't show up until I do the Show() on the containing form. How do I figure out what causes an error like this when
1. No changes were made to this UC
2. An error doesn't occur when instantiating the UI
3. Memory does not peak at all
4. Changing the first UC back to it's original form corrects the problem.
Thanks.
|
|
|
|
|
Commented out basically the entire UC and kept uncommenting until I found the line of code causing the error. It wasn't an OutOfMemoryException, due to the other changes the code was hit a reference to a NULL object.
There's got to be a better way to track those down...but misleading error messages don't help. Still not sure why the error reported as it did (after the other two UCs created and then upon parent form doing its Show method) because the problem does get encountered during form creation.
|
|
|
|
|
After performing calculation, a data need to be displayed. But the function SetWindowText() can only take parameter in string data type. How to convert the int and float into text form so that it can be displayed in the dialog using edit box (in MFC)?
|
|
|
|