Bitmap button or image with mouse click event

P

Pankaj S

Hi,

I have 2 questions, any help in this is highly appreciated

I have a scenario where I have 10 to 32 images, I have to find on which
image user clicked.
Which option is best suited for the this scenario:
1. Display images and get the mouse click event and check whether mouse
pointer is on particular image or not, if it is then get the image number.
2. Display those many image buttons and write button lick event.

Can I use Application.Run and Application.Exit more than once in one
application? What are the disadvantages of doing this? I want to use this to
keep form control in one class and navigate between forms using this
functions.

Thanks in advance.
Pankaj
 
G

Geoff Schwab [MSFT]

Hi Pankaj,

As far as the first goes, I would personally use 1 because I believe the
performance would be a bit better but the advantage to 2 is that you can
write a single image button control and easily re-use the code for every
image.

As far as using Application.Exit, I dug up the following from an old post:

Application.Exit is a hard exit like Win32's PostQuitMessage(). It's meant
to pop off all message pumps, unwind the callstack and return execution to
the system.

The correct way to shut down an app on Windows (Win32 or .NET) is to close
its main application window (i.e. Form.Close). Any window that's still
present after the main message pump ends needs to be manually closed. It's
good practice to clean up your windows by closing them before your app exits
by calling Form.Close or Form.Dispose, depending on the intended behavior

People need to remember that .NET's OnClosing() is the managed version of
Win32's WM_CLOSE and not WM_DESTROY.

Additionally, if you use form.Close(), your app will get a chance to clean
up stuff, close files, etc.. by handling a OnClosing or OnClosed event.
These events don't get called if you rip your app out w/ Application.Exit.

I have personally used Application.Run on occasion to create multiple forms
running on separate threads. You can do something like:

static public void StartForm()
{
form = new MyForm();
Application.Run(form);
}

Thread formThread = new Thread(new ThreadStart(StartForm));
formThread.Start();

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Pankaj S

Hi,

Thanks for the reply.
Regarding my second point, I want to navigate between forms one after
another and want to do this controlling through one class, like

void StartApplication()
{
ReturnType r = Application.Run(Form1);
if( r == something )
Application.Run(Form2);
else
Application.Run(Form3);
}

Each form will call Application.Exit to return to the StartApplication
function. Do you see any problem with this? If yes, what is the alternative?

Can I start the application without using Application.Run?

Thanks in advance,
Pankaj
 
G

Geoff Schwab [MSFT]

Hi Pankaj,

Using Application.Exit may work for your case but be aware of the caveats
mentioned in my last post.

You could also create a shell form which would create an instance of each
form as you need it and use Show. Then you could sit and wait on a variable
or something and close the form then move on to the next. It is also
possible to catch the close event in OnClosing and launch another form from
there. I have never actually tried this so I cannot say for sure what would
work best.

Have you looked at this FAQ item?
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx#4.4

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.

App
 
P

Pankaj S

Hi Geoff,

Thanks for the reply. I'll check out which option best suit me, I think one
main form to control other will be good one. Let me check.

Pankaj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top