|
Here is my code:
public partial class Form1 : Form
{
private Point old;
private bool isDragging = false;
private PictureBox[] myPic;
private int count = 0;
public Form1()
{
InitializeComponent();
begin();
}
public void begin()
{
myPic = new PictureBox[5];
}
private void button1_Click(object sender, EventArgs e)
{
myPic[count] = new PictureBox();
myPic[count].Image =System.Drawing.Image.FromFile("house.gif");
this.Controls.Add(myPic[count]);
myPic[count].MouseDown += new MouseEventHandler(Form1_MouseDown);
myPic[count].MouseMove += new MouseEventHandler(Form1_MouseMove);
myPic[count].MouseUp += new MouseEventHandler(Form1_MouseUp);
count++;
}
void Form1_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
}
void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging)
{
myPic[count-1].Left = myPic[count-1].Left + (e.X - old.X);
myPic[count-1].Top = myPic[count-1].Top + (e.Y - old.Y);
}
}
void Form1_MouseDown(object sender, MouseEventArgs e)
{
old.X = e.X;
old.Y = e.Y;
isDragging = true;
}
}
|
|
|
|
|
You should use a list, this will break after 5 items.
If you debug, is count 0 or 1 the second time ? It looks like it should be 1, but it seems likely it's not.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I can't debug because when i just move mouse on the picturebox, click event is not excuted but the mouse move event is excuted firstly. So the mouse move event is always happened while i can't reach the mouse click event.
By the way, count is always increased after clicking button1.
Please tell me how to correct the problem.
Thanks for replying.
-- modified at 5:45 Thursday 8th November, 2007
|
|
|
|
|
Okay, first off, don't use myPic[count-1] to access the control you want tp drag, you have the object 'sender' which is the control that was actually clicked, so if you use:
PictureBox temp = sender as PictureBox;
temp.Location.X = ...
temp.Location.Y =
...
Then you will always drag the picture box that you actually clicked.
Infact, if you add another picturebox like, currentPicBox or something and use that to find out which picbox was clicked. So, in the MouseDown event:
currentPicBox = sender as PictureBox;
and in the mouse move event:
currentPicBox.Location.X
...
-- modified at 6:09 Thursday 8th November, 2007
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
It works.
But when i clicked currentPicBox and move, there is more than 1 currentPicBox moving. That seems it appears and disappears, appears and disappears... until MouseUp event happens. So how to resolve?
Thanks for replying.
-- modified at 6:43 Thursday 8th November, 2007
|
|
|
|
|
I have the following scenario:
An application is using async. keys to verify itself to other apps. I've put the key in the key container with the following code:
CspParameters csp = new CspParameters();<br />
csp.KeyContainerName = "MyApplication"; <br />
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(csp);
The problem is that the (untrusted) user can make another application and easily get the key.
Is there any way to make a key accessible to my application only? The application could e.g. be identified by Strong Naming it...
PS: I am aware that one could run the app as a special user, and let that user have rights, but this application will launch other apps, and those other apps should preferably be run as the logged in user)
Jens Petter Abrahamsen
|
|
|
|
|
The only way this would be truely possible is if a web service (or another type of service) encrypts the key before saving to disk. The user would have no access to the web service, and therefore could not get the password used to encrypt the file. You would then need to use the same service to decrypt the file before using.
This service could be a simply Windows Service running on the same box as your application. You could then set the service to run as a user with priviliges (for example, to a directory) that your real user doesn't have.
Basically, if your application (running as the user) can encrypt/decrypt the file then the user would be able to do it without your application. Some developers embed a password in their application binaries and use that for encryption and decryption. A technical user could extract the password from your binary (regardless of whether it's in .Net).
You can use impersonation[^] to launch applications as different users.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thank you very much for your reply!
I have one follow-up question:
If I create a Windows Service, running as a privileged user, I agree that the key (on disk) is safe. But when my application asks the service for the key, how can the Windows Service know that it gives the (unencrypted) key to the correct program? Is there a secure way for a WinForm program to communicate with a service?
Jens Petter Abrahamsen
|
|
|
|
|
The idea is that you pass the encrypted data to the windows service and it would decrypt it for you (and encrypt). It would not provide the password to your application.
As far as whether it's talking to the correct program. The user would have to have enough restrictions that they cannot run another application that can talk to your service.
The best way to think of it is, anything your application can do, another application could do. So you need to restrict the users right enough that they can't use "another application".
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
TJoe wrote: The user would have no easy access to the web service, and therefore could not get the password used to encrypt the file without jumping through hoops .
Edited for correctness. If someone really wanted to swipe your password they could either sniff packets, or run your application in a disassembler/debugger environment to lift the password out of memory after it's been retrieved.
--
If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.
|
|
|
|
|
Well, the idea was that service would do the encrypting and decrypting. So the application would pass the encrypted data to the service, which would decrypt it and send it back.
But you are right, the user could still get at the decrypted data in memory or through a packet sniffer. The user could get the decrypted data from memory even if it was never encrypted and/or sent to the service.
See my other reply, but this process only works if the user is restricted enough that they can't run a program that would sniff the packets, view memory contents, or duplicate his application.
It's definitely a complex problem.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi all,
I need to extract game statistics in my application for games like CS 1.6, Half life2, halo 1 and halo 2,battlefield etc....Is there any library that I can use to extract the game info??
Shoaib
|
|
|
|
|
Hello guys,
I want to connect to and edit ms access database. The oledb functionality is
not present for .NET CF. When I try to build the solution, it gives me an
error "are you missing an assembly reference?" PS. I am coding in C#
I would like to know if there is a way to connect ms access database, and if
there is a way then what is it?
If not, then how should I go about dealing with this problem?
A little info on my project - I am doing a vending machine project for my
senior design where I have to take out all the logic circuit and replace it
with some thing new. I am using EBOX 2300 as the main control board, which
will have signals coming in and out to control other modules of the project.
The database is for keeping pricing information, authorized user information
such as user name and password (we are implementing student id and rfid card
purchases), and other things.
-- modified at 3:04 Thursday 8th November, 2007
Arsu
|
|
|
|
|
|
How can a winform table layout panel be constructed with mutiple columns on the top row and only one single column on the bottom row?
|
|
|
|
|
TableLayout panel must be simetric. You can solve this creating a panel and add inside the tablelayout panel and a panel. Set Dock of panel to bottom, and tlp Dock property to Fill.
Visit my blog at http://dotnetforeveryone.blogspot.com
|
|
|
|
|
Use ColumnSpan Property of control that inside the first bottom row cell. Set it to desired number of columns...
hope that helps
zilo
|
|
|
|
|
Hey all,
I know there is ton of info out there about my problem but i just don't seem to get it now in the right time.
Again this might be a piece of cake but it is hard for me to do it, here it goes:
I have developed 3 apps 2 to be run on windows pc, server/client, and one for a pocket pc, all of them need a login form, here is where my problem comes, to be accessed. I just don't know how to add buttons and labels to the newly created form. I was thinking on creating a separate app for the login and then calling the main application, but the problem will be how to block the main application from starting when is double clicked?
And sorry to ask again does anybody has used a microsoft finger reader without any 3rd party sdk? Or have done it with GrFinger ? If please help to read images from the finger print reader.
I am so desperate to finish this project that i am sleeping barely 2 hours a day. So far all i am missing is the login form, Active Directory management to verify the users and the fingerprint reader...
Thanks all in advance,
ps: People I admire each one of you who know this much C# programming, this learning in the process has been a terrific expirience thanks to the existence of C#, i just hoped it could have been less stressful.
Luis E Tineo S
|
|
|
|
|
kingletas wrote: I just don't know how to add buttons and labels to the newly created form
So how did you do the other forms in your app ?
You need to integrate the login with your app, you can't factor it out. It needs to be a form within your app. You can't have a login app that runs the main app. The only way to do that would be for the app to require a key on the command line, but it's not a good idea at all.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hey,
Well since i am learning in the process I was letting VS2005 to do it for me but now i am doing it myself because i now know how to it.
I just forgot about the Form.Controls.Add method...
I think i need some rest...
Thanks,
Luis E Tineo S
|
|
|
|
|
Hi everybody,
I have developed a website using C# & Visual Studio 2005. The website must be able to get system information (RAM, HDD etc) from the user's computer and display it on the screen.
When I run the website on localhost, everything works out fine. But as soon as I install the website on a IIS 6.0 webserver and try to run it from a client computer, I get an error that says "Object not referenced". What on earth is going on here? Can anyone please help?
Thanx,
Michelle
|
|
|
|
|
|
Hi,
try below code.
label1.Attributes["onmouseover"]="alert('Hi');";
hope it will help you.
Thanks,
Sun Rays
|
|
|
|
|
This is not the ASP.NET forum
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
HI,
Thanx for ur reply . I want the code for getting on mouse move value (when ever mouse goes on to a label,linkbutton,.......)I
should get that value.Plz help me with the code
|
|
|
|